view 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
line wrap: on
line source

using System;
using System.Reflection;
using System.Runtime.ExceptionServices;

namespace Implab {
    static class ExceptionHelpers {
        public static Exception Rethrow(this Exception that) {
            ExceptionDispatchInfo.Capture(that).Throw();
            return new TargetInvocationException(that);
        }

        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);
            else
                return new TargetInvocationException(that);
        }
    }
}