C# Class Loyc.ExceptionExt

Extension methods for exceptions.
Afficher le fichier Open project: qwertie/ecsharp

Méthodes publiques

Méthode Description
AppendDataList ( IDictionary dict, StringBuilder sb, string linePrefix, string keyValueSeparator, string newLine ) : StringBuilder
DataList ( this ex ) : string

Converts Exception.Data to a string, separating each key-value pair by a newline.

DataList ( this ex, string linePrefix, string keyValueSeparator, string newLine ) : string

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.

Description ( this ex ) : string
Description ( this ex, bool addStackTrace, string lineSeparator = "\n\n" ) : string

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).

DescriptionAndStackTrace ( this ex ) : string Adds a stack trace.
ExceptionMessageAndType ( this ex ) : string

Returns a string of the form "{ex.Message} ({ex.GetType().Name})".

InnermostException ( this ex ) : Exception

Gets the innermost InnerException, or ex itself if there are no inner exceptions.

PreserveStackTrace ( this exception ) : void

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.

ToDetailedString ( this ex ) : string

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.

If maxInnerExceptions is not given, the default is 3.

ToDetailedString ( this ex, int maxInnerExceptions ) : string

Method Details

AppendDataList() public static méthode

public static AppendDataList ( IDictionary dict, StringBuilder sb, string linePrefix, string keyValueSeparator, string newLine ) : StringBuilder
dict IDictionary
sb StringBuilder
linePrefix string
keyValueSeparator string
newLine string
Résultat StringBuilder

DataList() public static méthode

Converts Exception.Data to a string, separating each key-value pair by a newline.
public static DataList ( this ex ) : string
ex this
Résultat string

DataList() public static méthode

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.
public static DataList ( this ex, string linePrefix, string keyValueSeparator, string newLine ) : string
ex this
linePrefix string
keyValueSeparator string
newLine string
Résultat string

Description() public static méthode

public static Description ( this ex ) : string
ex this
Résultat string

Description() public static méthode

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).
public static Description ( this ex, bool addStackTrace, string lineSeparator = "\n\n" ) : string
ex this
addStackTrace bool If true, the stack trace of the outermost /// exception is added to the end of the message (not the innermost /// exception, because the inner stack trace gets truncated. TODO: /// investigate whether the full stack trace can be reconstructed).
lineSeparator string Separator between different exceptions and /// before the stack trace.
Résultat string

DescriptionAndStackTrace() public static méthode

Adds a stack trace.
public static DescriptionAndStackTrace ( this ex ) : string
ex this
Résultat string

ExceptionMessageAndType() public static méthode

Returns a string of the form "{ex.Message} ({ex.GetType().Name})".
public static ExceptionMessageAndType ( this ex ) : string
ex this
Résultat string

InnermostException() public static méthode

Gets the innermost InnerException, or ex itself if there are no inner exceptions.
ex is null.
public static InnermostException ( this ex ) : Exception
ex this
Résultat System.Exception

PreserveStackTrace() public static méthode

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.
public static PreserveStackTrace ( this exception ) : void
exception this
Résultat void

ToDetailedString() public static méthode

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.
If maxInnerExceptions is not given, the default is 3.
public static ToDetailedString ( this ex ) : string
ex this
Résultat string

ToDetailedString() public static méthode

public static ToDetailedString ( this ex, int maxInnerExceptions ) : string
ex this
maxInnerExceptions int
Résultat string