void OnException(Exception exception)
{
Trace.WriteLine(TraceLevel.Error, "Exception occurred: {0}", exception.ToString());
AmqpException amqpException = exception as AmqpException;
Error error = amqpException != null ?
amqpException.Error :
new Error() { Condition = ErrorCode.InternalError, Description = exception.Message };
if (this.state < State.ClosePipe)
{
try
{
this.Close(0, error);
}
catch
{
this.state = State.End;
}
}
else
{
this.state = State.End;
}
if (this.state == State.End)
{
this.OnEnded(error);
}
}