Provide Exception object in ErrorEventArgs if possible

This commit is contained in:
Frank Razenberg 2014-08-20 16:20:10 +02:00
parent e7aa1a469d
commit e2203986fd
2 changed files with 21 additions and 10 deletions

View File

@ -43,14 +43,16 @@ namespace WebSocketSharp
#region Private Fields #region Private Fields
private string _message; private string _message;
private Exception _exception;
#endregion #endregion
#region Internal Constructors #region Internal Constructors
internal ErrorEventArgs (string message) internal ErrorEventArgs (string message, Exception exc = null)
{ {
_message = message; _message = message;
_exception = exc;
} }
#endregion #endregion
@ -69,6 +71,15 @@ namespace WebSocketSharp
} }
} }
/// <summary>
/// Gets the exception.
/// </summary>
public Exception Exception {
get {
return _exception;
}
}
#endregion #endregion
} }
} }

View File

@ -604,7 +604,7 @@ namespace WebSocketSharp
} }
catch (Exception ex) { catch (Exception ex) {
_logger.Fatal (ex.ToString ()); _logger.Fatal (ex.ToString ());
error ("An exception has occurred while OnClose."); error ("An exception has occurred while OnClose.", ex);
} }
} }
@ -856,10 +856,10 @@ namespace WebSocketSharp
_messageEventQueue.Enqueue (e); _messageEventQueue.Enqueue (e);
} }
private void error (string message) private void error (string message, Exception exc = null)
{ {
try { try {
OnError.Emit (this, new ErrorEventArgs (message)); OnError.Emit (this, new ErrorEventArgs (message, exc));
} }
catch (Exception ex) { catch (Exception ex) {
_logger.Fatal ("An exception has occurred while OnError:\n" + ex.ToString ()); _logger.Fatal ("An exception has occurred while OnError:\n" + ex.ToString ());
@ -931,7 +931,7 @@ namespace WebSocketSharp
else else
_logger.Error (reason); _logger.Error (reason);
error (message ?? code.GetMessage ()); error (message ?? code.GetMessage (), exception);
if (_readyState == WebSocketState.Connecting && !_client) if (_readyState == WebSocketState.Connecting && !_client)
Close (HttpStatusCode.BadRequest); Close (HttpStatusCode.BadRequest);
else else
@ -1068,7 +1068,7 @@ namespace WebSocketSharp
} }
catch (Exception ex) { catch (Exception ex) {
_logger.Fatal (ex.ToString ()); _logger.Fatal (ex.ToString ());
error ("An exception has occurred while sending a data."); error ("An exception has occurred while sending a data.", ex);
} }
finally { finally {
if (compressed) if (compressed)
@ -1155,7 +1155,7 @@ namespace WebSocketSharp
} }
catch (Exception ex) { catch (Exception ex) {
_logger.Fatal (ex.ToString ()); _logger.Fatal (ex.ToString ());
error ("An exception has occurred while callback."); error ("An exception has occurred while callback.", ex);
} }
}, },
null); null);
@ -2046,7 +2046,7 @@ namespace WebSocketSharp
}, },
ex => { ex => {
_logger.Fatal (ex.ToString ()); _logger.Fatal (ex.ToString ());
error ("An exception has occurred while sending a data."); error ("An exception has occurred while sending a data.", ex);
}); });
} }