Extension methods for exceptions.
|
static string | ExceptionMessageAndType (this Exception ex) |
| Returns a string of the form "{ex.Message} ({ex.GetType().Name})". More...
|
|
static Exception | InnermostException (this Exception ex) |
| Gets the innermost InnerException, or ex itself if there are no inner exceptions. More...
|
|
static string | Description (this Exception ex) |
|
static string | DescriptionAndStackTrace (this Exception ex) |
|
static string | Description (this Exception ex, bool addStackTrace, string lineSeparator="\n\n") |
| Gets a description of the exception in the form "{ex.Message} ({ex.GetType().Name})". If the exception has InnerExceptions, these are printed afterward in the form "Inner exception: {ex.Message} ({ex.GetType().Name})" and separated from the outer exception by "\n\n" (or a string of your choosing). More...
|
|
static string | ToDetailedString (this Exception ex) |
| Returns a string containing the exception type, message, Data pairs (if any) and stack strace, followed by the type, message and stack strace of inner exceptions, if any. More...
|
|
static string | ToDetailedString (this Exception ex, int maxInnerExceptions) |
|
static string | DataList (this Exception ex) |
| Converts Exception.Data to a string, separating each key-value pair by a newline. More...
|
|
static string | DataList (this Exception ex, string linePrefix, string keyValueSeparator, string newLine) |
| Converts Exception.Data to a string, separating each key from each value with keyValueSeparator , prepending each line by linePrefix , and separating each pair with newLine , which may or may not be "\n", your choice. More...
|
|
static StringBuilder | AppendDataList (IDictionary dict, StringBuilder sb, string linePrefix, string keyValueSeparator, string newLine) |
|
static void | PreserveStackTrace (this Exception exception) |
| Calls an internal method of Exception that records an exception's stack trace so that the stack trace does not change if the exception is rethrown (e.g. on another thread). More...
|
|
static void Loyc.ExceptionExt.PreserveStackTrace |
( |
this Exception |
exception | ) |
|
|
inlinestatic |
Calls an internal method of Exception that records an exception's stack trace so that the stack trace does not change if the exception is rethrown (e.g. on another thread).
Exception ex = null; var thread = new ThreadEx(() => { try { SomethingThatMightThrowOrTakeForever(); } catch (Exception e) { ex = e; ex.PreserveStackTrace(); } }); thread.Start(); if (!thread.Join(timeout)) { thread.Abort(); thread.Join(timeout); } if (ex != null) throw ex; // includes stack trace from the other thread
Note: when rethrowing an exception that was just caught, you should always use "catch;" instead of calling this method.
static string Loyc.ExceptionExt.ToDetailedString |
( |
this Exception |
ex | ) |
|
|
inlinestatic |