comparison Implab/ExceptionHelpers.cs @ 249:d82909310094 v3

Implab.Test moved to xunit Complete set of PromiseHelpers (Then, Catch, Finally) Removed obsolete types ICancellable, ICancellationToken
author cin
date Wed, 31 Jan 2018 11:28:38 +0300
parents 5cb4826c2c2a
children
comparison
equal deleted inserted replaced
248:5cb4826c2c2a 249:d82909310094
1 using System; 1 using System;
2 using System.Reflection; 2 using System.Reflection;
3 using System.Runtime.ExceptionServices; 3 using System.Runtime.ExceptionServices;
4 4
5 namespace Implab { 5 namespace Implab {
6 public static class ExceptionHelpers { 6 static class ExceptionHelpers {
7 public static void Rethrow(this Exception that) { 7 public static Exception Rethrow(this Exception that) {
8 ExceptionDispatchInfo.Capture(that).Throw(); 8 ExceptionDispatchInfo.Capture(that).Throw();
9 return new TargetInvocationException(that);
9 } 10 }
10 11
11 public static void ThrowInvocationException(this Exception that) { 12 public static Exception Wrap(this Exception that) {
12 if (that is OperationCanceledException) 13 if (that == null)
13 throw new OperationCanceledException("Operation cancelled", that); 14 return new Exception();
15 else if (that is OperationCanceledException)
16 return new OperationCanceledException("The operation has been cancelled", that);
14 else 17 else
15 throw new TargetInvocationException(that); 18 return new TargetInvocationException(that);
16 } 19 }
17 } 20 }
18 } 21 }