diff --git a/websocket-sharp/ErrorEventArgs.cs b/websocket-sharp/ErrorEventArgs.cs index 85685f09..d72fb295 100644 --- a/websocket-sharp/ErrorEventArgs.cs +++ b/websocket-sharp/ErrorEventArgs.cs @@ -43,20 +43,27 @@ namespace WebSocketSharp #region Private Fields private string _message; + private Exception _exception; #endregion #region Internal Constructors internal ErrorEventArgs (string message) + : this (message, null) + { + } + + internal ErrorEventArgs (string message, Exception exception) { _message = message; + _exception = exception; } #endregion #region Public Properties - + /// /// Gets the error message. /// @@ -69,6 +76,18 @@ namespace WebSocketSharp } } + /// + /// Gets the exception that caused the error. + /// + /// A instance that represents the cause of the error, + /// or if the error isn't due to an exception. + /// + public Exception Exception { + get { + return _exception; + } + } + #endregion } } diff --git a/websocket-sharp/WebSocket.cs b/websocket-sharp/WebSocket.cs index ef52fe9f..521355d5 100644 --- a/websocket-sharp/WebSocket.cs +++ b/websocket-sharp/WebSocket.cs @@ -604,7 +604,7 @@ namespace WebSocketSharp } catch (Exception ex) { _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); } - private void error (string message) + private void error (string message, Exception exc = null) { try { - OnError.Emit (this, new ErrorEventArgs (message)); + OnError.Emit (this, new ErrorEventArgs (message, exc)); } catch (Exception ex) { _logger.Fatal ("An exception has occurred while OnError:\n" + ex.ToString ()); @@ -931,7 +931,7 @@ namespace WebSocketSharp else _logger.Error (reason); - error (message ?? code.GetMessage ()); + error (message ?? code.GetMessage (), exception); if (_readyState == WebSocketState.Connecting && !_client) Close (HttpStatusCode.BadRequest); else @@ -1068,7 +1068,7 @@ namespace WebSocketSharp } catch (Exception ex) { _logger.Fatal (ex.ToString ()); - error ("An exception has occurred while sending a data."); + error ("An exception has occurred while sending a data.", ex); } finally { if (compressed) @@ -1155,7 +1155,7 @@ namespace WebSocketSharp } catch (Exception ex) { _logger.Fatal (ex.ToString ()); - error ("An exception has occurred while callback."); + error ("An exception has occurred while callback.", ex); } }, null); @@ -2046,7 +2046,7 @@ namespace WebSocketSharp }, ex => { _logger.Fatal (ex.ToString ()); - error ("An exception has occurred while sending a data."); + error ("An exception has occurred while sending a data.", ex); }); }