annotate Implab/ExceptionHelpers.cs @ 255:b00441e04738 v3

Adde workaround to the behaviour of the logical operations stack in conjuction with async/await methods
author cin
date Wed, 04 Apr 2018 15:38:48 +0300
parents d82909310094
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
248
5cb4826c2c2a Added awaiters to promises
cin
parents:
diff changeset
1 using System;
5cb4826c2c2a Added awaiters to promises
cin
parents:
diff changeset
2 using System.Reflection;
5cb4826c2c2a Added awaiters to promises
cin
parents:
diff changeset
3 using System.Runtime.ExceptionServices;
5cb4826c2c2a Added awaiters to promises
cin
parents:
diff changeset
4
5cb4826c2c2a Added awaiters to promises
cin
parents:
diff changeset
5 namespace Implab {
249
d82909310094 Implab.Test moved to xunit
cin
parents: 248
diff changeset
6 static class ExceptionHelpers {
d82909310094 Implab.Test moved to xunit
cin
parents: 248
diff changeset
7 public static Exception Rethrow(this Exception that) {
248
5cb4826c2c2a Added awaiters to promises
cin
parents:
diff changeset
8 ExceptionDispatchInfo.Capture(that).Throw();
249
d82909310094 Implab.Test moved to xunit
cin
parents: 248
diff changeset
9 return new TargetInvocationException(that);
248
5cb4826c2c2a Added awaiters to promises
cin
parents:
diff changeset
10 }
5cb4826c2c2a Added awaiters to promises
cin
parents:
diff changeset
11
249
d82909310094 Implab.Test moved to xunit
cin
parents: 248
diff changeset
12 public static Exception Wrap(this Exception that) {
d82909310094 Implab.Test moved to xunit
cin
parents: 248
diff changeset
13 if (that == null)
d82909310094 Implab.Test moved to xunit
cin
parents: 248
diff changeset
14 return new Exception();
d82909310094 Implab.Test moved to xunit
cin
parents: 248
diff changeset
15 else if (that is OperationCanceledException)
d82909310094 Implab.Test moved to xunit
cin
parents: 248
diff changeset
16 return new OperationCanceledException("The operation has been cancelled", that);
248
5cb4826c2c2a Added awaiters to promises
cin
parents:
diff changeset
17 else
249
d82909310094 Implab.Test moved to xunit
cin
parents: 248
diff changeset
18 return new TargetInvocationException(that);
248
5cb4826c2c2a Added awaiters to promises
cin
parents:
diff changeset
19 }
5cb4826c2c2a Added awaiters to promises
cin
parents:
diff changeset
20 }
5cb4826c2c2a Added awaiters to promises
cin
parents:
diff changeset
21 }