ExceptionHelpers.cs
20 lines
| 700 B
| text/x-csharp
|
CSharpLexer
/ Implab / ExceptionHelpers.cs
cin
|
r248 | using System; | |
using System.Reflection; | |||
using System.Runtime.ExceptionServices; | |||
namespace Implab { | |||
cin
|
r249 | static class ExceptionHelpers { | |
public static Exception Rethrow(this Exception that) { | |||
cin
|
r248 | ExceptionDispatchInfo.Capture(that).Throw(); | |
cin
|
r249 | return new TargetInvocationException(that); | |
cin
|
r248 | } | |
cin
|
r249 | public static Exception Wrap(this Exception that) { | |
if (that == null) | |||
return new Exception(); | |||
else if (that is OperationCanceledException) | |||
return new OperationCanceledException("The operation has been cancelled", that); | |||
cin
|
r248 | else | |
cin
|
r249 | return new TargetInvocationException(that); | |
cin
|
r248 | } | |
} | |||
} |