public void PrepareForRethrow_PreservesStackTrace()
        {
            string originalStackTrace = null;

            try
            {
                Exception preservedException = null;
                try
                {
                    ThrowNotImplementedException();
                }
                catch (NotImplementedException ex)
                {
                    originalStackTrace = ex.StackTrace;
                    preservedException = ex;
                }

                throw ExceptionHelpers.PrepareForRethrow(preservedException);
            }
            catch (NotImplementedException ex)
            {
                Assert.IsTrue(ex.StackTrace.StartsWith(originalStackTrace));
                return;
            }
        }
Esempio n. 2
0
 /// <summary>
 /// Waits for the task to complete, unwrapping any exceptions.
 /// </summary>
 /// <param name="task">The task. May not be <c>null</c>.</param>
 /// <param name="cancellationToken">A cancellation token to observe while waiting for the task to complete.</param>
 /// <exception cref="OperationCanceledException">The <paramref name="cancellationToken"/> was cancelled before the <paramref name="task"/> completed, or the <paramref name="task"/> raised an <see cref="OperationCanceledException"/>.</exception>
 public static void WaitAndUnwrapException(this Task task, CancellationToken cancellationToken)
 {
     try {
         task.Wait(cancellationToken);
     } catch (AggregateException ex) {
         throw ExceptionHelpers.PrepareForRethrow(ex.InnerException);
     }
 }
Esempio n. 3
0
 /// <summary>
 /// Waits for the task to complete, unwrapping any exceptions.
 /// </summary>
 /// <typeparam name="TResult">The type of the result of the task.</typeparam>
 /// <param name="task">The task. May not be <c>null</c>.</param>
 /// <param name="cancellationToken">A cancellation token to observe while waiting for the task to complete.</param>
 /// <returns>The result of the task.</returns>
 /// <exception cref="OperationCanceledException">The <paramref name="cancellationToken"/> was cancelled before the <paramref name="task"/> completed, or the <paramref name="task"/> raised an <see cref="OperationCanceledException"/>.</exception>
 public static TResult WaitAndUnwrapException <TResult>(this Task <TResult> task, CancellationToken cancellationToken)
 {
     try {
         task.Wait(cancellationToken);
         return(task.Result);
     } catch (AggregateException ex) {
         throw ExceptionHelpers.PrepareForRethrow(ex.InnerException);
     }
 }
Esempio n. 4
0
 /// <summary>
 /// Waits for the task to complete, unwrapping any exceptions.
 /// </summary>
 /// <param name="task">The task. May not be <c>null</c>.</param>
 /// <param name="cancellationToken">A cancellation token to observe while waiting for the task to complete.</param>
 /// <exception cref="OperationCanceledException">The <paramref name="cancellationToken"/> was cancelled before the <paramref name="task"/> completed, or the <paramref name="task"/> raised an <see cref="OperationCanceledException"/>.</exception>
 public static void WaitAndUnwrapException(this Task task, CancellationToken cancellationToken)
 {
     if (task == null)
     {
         throw new ArgumentNullException(nameof(task));
     }
     try
     {
         task.Wait(cancellationToken);
     }
     catch (AggregateException ex)
     {
         throw ExceptionHelpers.PrepareForRethrow(ex.InnerException);
     }
 }
Esempio n. 5
0
 /// <summary>
 /// Waits for the task to complete, unwrapping any exceptions.
 /// </summary>
 /// <typeparam name="TResult">The type of the result of the task.</typeparam>
 /// <param name="task">The task. May not be <c>null</c>.</param>
 /// <param name="cancellationToken">A cancellation token to observe while waiting for the task to complete.</param>
 /// <returns>The result of the task.</returns>
 /// <exception cref="OperationCanceledException">The <paramref name="cancellationToken"/> was cancelled before the <paramref name="task"/> completed, or the <paramref name="task"/> raised an <see cref="OperationCanceledException"/>.</exception>
 public static TResult WaitAndUnwrapException <TResult>(this Task <TResult> task, CancellationToken cancellationToken)
 {
     if (task is null)
     {
         throw new ArgumentNullException(nameof(task));
     }
     try
     {
         task.Wait(cancellationToken);
         return(task.Result);
     }
     catch (AggregateException ex)
     {
         throw ExceptionHelpers.PrepareForRethrow(ex.InnerException);
     }
 }