C# Класс Loyc.ExceptionExt

Extension methods for exceptions.
Показать файл Открыть проект

Открытые методы

Метод Описание
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

Описание методов

AppendDataList() публичный статический Метод

public static AppendDataList ( IDictionary dict, StringBuilder sb, string linePrefix, string keyValueSeparator, string newLine ) : StringBuilder
dict IDictionary
sb StringBuilder
linePrefix string
keyValueSeparator string
newLine string
Результат StringBuilder

DataList() публичный статический Метод

Converts Exception.Data to a string, separating each key-value pair by a newline.
public static DataList ( this ex ) : string
ex this
Результат string

DataList() публичный статический Метод

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
Результат string

Description() публичный статический Метод

public static Description ( this ex ) : string
ex this
Результат string

Description() публичный статический Метод

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.
Результат string

DescriptionAndStackTrace() публичный статический Метод

Adds a stack trace.
public static DescriptionAndStackTrace ( this ex ) : string
ex this
Результат string

ExceptionMessageAndType() публичный статический Метод

Returns a string of the form "{ex.Message} ({ex.GetType().Name})".
public static ExceptionMessageAndType ( this ex ) : string
ex this
Результат string

InnermostException() публичный статический Метод

Gets the innermost InnerException, or ex itself if there are no inner exceptions.
ex is null.
public static InnermostException ( this ex ) : Exception
ex this
Результат System.Exception

PreserveStackTrace() публичный статический Метод

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
Результат void

ToDetailedString() публичный статический Метод

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
Результат string

ToDetailedString() публичный статический Метод

public static ToDetailedString ( this ex, int maxInnerExceptions ) : string
ex this
maxInnerExceptions int
Результат string