本文整理汇总了C#中AggregateException类的典型用法代码示例。如果您正苦于以下问题:C# AggregateException类的具体用法?C# AggregateException怎么用?C# AggregateException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
AggregateException类属于命名空间,在下文中一共展示了AggregateException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ThrowAsync
/// <summary>Throws the exception on the thread pool.</summary>
/// <param name="exception">The exception to propagate.</param>
/// <param name="targetContext">
/// The target context on which to propagate the exception; otherwise, <see langword="null"/> to use the thread
/// pool.
/// </param>
internal static void ThrowAsync(Exception exception, SynchronizationContext targetContext)
{
if (targetContext != null)
{
try
{
targetContext.Post(
state =>
{
throw PrepareExceptionForRethrow((Exception)state);
}, exception);
return;
}
catch (Exception ex)
{
exception = new AggregateException(exception, ex);
}
}
#if NET45PLUS
Task.Run(() =>
{
throw PrepareExceptionForRethrow(exception);
});
#else
ThreadPool.QueueUserWorkItem(state =>
{
throw PrepareExceptionForRethrow((Exception)state);
}, exception);
#endif
}
示例2: ThrowAsync
internal static void ThrowAsync(Exception exception, SynchronizationContext targetContext)
{
if (targetContext != null)
{
try
{
targetContext.Post(delegate(object state)
{
throw AsyncServices.PrepareExceptionForRethrow((Exception)state);
}, exception);
return;
}
catch (Exception ex)
{
exception = new AggregateException(new Exception[]
{
exception,
ex
});
}
}
ThreadPool.QueueUserWorkItem(delegate(object state)
{
throw AsyncServices.PrepareExceptionForRethrow((Exception)state);
}, exception);
}
示例3: LogException
/// <summary>
/// Function to log exception except disposed exception.
/// </summary>
/// <param name="aggregateException">Aggregate Exception</param>
private static void LogException(AggregateException aggregateException)
{
if (aggregateException != null)
{
aggregateException.Handle((ex) => HandleException(ex));
}
}
示例4: HandleError
private void HandleError(AggregateException ae)
{
if (ae.InnerException != null)
{
MessageBox.Show("An error occurred while uploading the image to imgur.com. Please try again.", "SnagitImgur", MessageBoxButtons.OK, MessageBoxIcon.Warning);
ae.InnerException.ToExceptionless().Submit();
}
}
示例5: HandleAggregateException
Tuple<string, bool> HandleAggregateException(AggregateException aggregrateException,
ReportExceptionEventArgs et) {
Tuple<string, bool> handled = null;
foreach (var error in aggregrateException.Flatten().InnerExceptions) {
if (handled == null || handled.Item1 == null)
handled = InternalHandler(error, et); // Does not set the loader to true
}
return handled;
}
示例6: HandleFault
public void HandleFault(AggregateException ex)
{
Logger.Error(ex.Message, ex);
var message = IoC.Get<MessageBoxViewModel>();
message.DisplayName = "Error";
message.Content = new ErrorInfo();
message.DismissAction = () => NavigateToHome();
message.DismissTimeout = 10000;
NavigateToScreen(message);
}
示例7: HandleException
private static void HandleException(AggregateException ex)
{
if (ex.InnerExceptions.OfType<TaskCanceledException>()
.Any())
{
Console.WriteLine("Task was canceled...");
Log.Trace("Task was canceled");
}
else
{
Log.Error(ex, "Task proccessing exception");
}
}
示例8: SimpleInnerExceptionTestCase
public void SimpleInnerExceptionTestCase ()
{
var message = "Foo";
var inner = new ApplicationException (message);
var ex = new AggregateException (inner);
Assert.IsNotNull (ex.InnerException);
Assert.IsNotNull (ex.InnerExceptions);
Assert.AreEqual (inner, ex.InnerException);
Assert.AreEqual (1, ex.InnerExceptions.Count);
Assert.AreEqual (inner, ex.InnerExceptions[0]);
Assert.AreEqual (message, ex.InnerException.Message);
}
示例9: EventForFailedOperation
internal static IProvisioningEvent EventForFailedOperation(AggregateException exception)
{
HttpStatusCode httpStatus;
if (ProvisioningErrorHandling.TryGetHttpStatusCode(exception, out httpStatus))
{
return ProvisioningErrorHandling.IsTransientError(exception)
? (IProvisioningEvent)new DiscoveryFailedTransientEvent(exception, httpStatus)
: new DiscoveryFailedPermanentEvent(exception, httpStatus);
}
return ProvisioningErrorHandling.IsTransientError(exception)
? (IProvisioningEvent)new DiscoveryFailedTransientEvent(exception)
: new DiscoveryFailedPermanentEvent(exception);
}
示例10: Start
public void Start()
{
m_InstanciedServiceList = new List<object>();
var list = GetServiceTypeList();
System.Diagnostics.Trace.WriteLine(string.Format("{0} services found", list.Count()));
m_ServiceList = list.Where(i => !i.Item1).Select(i => Type.GetType(i.Item2)).ToList();
var autoUpdateServiceHostList = list.Where(i => i.Item1).Select(i => i.Item2).ToList();
var failList = new List<Exception>();
StartServices(failList);
if (failList.Count > 0)
{
var failStartException = new AggregateException("Start services failed", failList);
throw failStartException;
}
}
示例11: GetMessageAndStackTrace
public static String GetMessageAndStackTrace(AggregateException e)
{
if (e == null)
{
throw new ArgumentNullException("e", "AggregateException can not be null.");
}
var sb = new StringBuilder();
foreach (Exception innerException in e.InnerExceptions)
{
sb.AppendLine(innerException.Message);
sb.AppendLine("\t" + innerException.StackTrace);
}
return sb.ToString();
}
示例12: ThrowAsync
/// <summary>Throws the exception on the ThreadPool.</summary>
/// <param name="exception">The exception to propagate.</param>
/// <param name="targetContext">The target context on which to propagate the exception. Null to use the ThreadPool.</param>
internal static void ThrowAsync(Exception exception, SynchronizationContext targetContext)
{
// If the user supplied a SynchronizationContext...
if (targetContext != null)
{
try
{
// Post the throwing of the exception to that context, and return.
targetContext.Post(state => { throw PrepareExceptionForRethrow((Exception)state); }, exception);
return;
}
catch (Exception postException)
{
// If something goes horribly wrong in the Post, we'll
// propagate both exceptions on the ThreadPool
exception = new AggregateException(exception, postException);
}
}
// Propagate the exception(s) on the ThreadPool
ThreadPool.QueueUserWorkItem(state => { throw PrepareExceptionForRethrow((Exception)state); }, exception);
}
示例13: Exception
public void Should_persist_and_unwrap_multiple_nested_original_exception_in_requestexecutionexception_with_exceptions_on_multiple_levels()
{
// Given
var expectedException1 = new Exception();
var expectedException2 = new Exception();
var expectedException3 = new Exception();
var expectedException4 = new Exception();
var expectgedInnerExceptions = 4;
var exceptionsListInner = new List<Exception>() { expectedException1, expectedException2, expectedException3 };
var expectedExceptionInner = new AggregateException(exceptionsListInner);
var exceptionsListOuter = new List<Exception>() { expectedExceptionInner, expectedException4 };
var aggregateExceptionOuter = new AggregateException(exceptionsListOuter);
var resolvedRoute = new ResolveResult(
new FakeRoute(),
DynamicDictionary.Empty,
null,
null,
null);
A.CallTo(() => resolver.Resolve(A<NancyContext>.Ignored)).Returns(resolvedRoute);
A.CallTo(() => this.requestDispatcher.Dispatch(context, A<CancellationToken>._))
.Returns(TaskHelpers.GetFaultedTask<Response>(aggregateExceptionOuter));
var pipelines = new Pipelines();
pipelines.OnError.AddItemToStartOfPipeline((ctx, exception) => null);
engine.RequestPipelinesFactory = (ctx) => pipelines;
var request = new Request("GET", "/", "http");
// When
var result = this.engine.HandleRequest(request);
var returnedException = result.Items["ERROR_EXCEPTION"] as RequestExecutionException;
// Then
var returnedInnerException = returnedException.InnerException as AggregateException;
returnedInnerException.ShouldBeOfType(typeof(AggregateException));
Assert.Equal(expectgedInnerExceptions, returnedInnerException.InnerExceptions.Count);
}
示例14: Should_persist_and_unwrap_original_exception_in_requestexecutionexception
public void Should_persist_and_unwrap_original_exception_in_requestexecutionexception()
{
// Given
var expectedException = new Exception();
var aggregateException = new AggregateException(expectedException);
var resolvedRoute = new ResolveResult(
new FakeRoute(),
DynamicDictionary.Empty,
null,
null,
null);
A.CallTo(() => resolver.Resolve(A<NancyContext>.Ignored)).Returns(resolvedRoute);
A.CallTo(() => this.requestDispatcher.Dispatch(context, A<CancellationToken>._))
.Returns(TaskHelpers.GetFaultedTask<Response>(aggregateException));
var pipelines = new Pipelines();
pipelines.OnError.AddItemToStartOfPipeline((ctx, exception) => null);
engine.RequestPipelinesFactory = (ctx) => pipelines;
var request = new Request("GET", "/", "http");
// When
var result = this.engine.HandleRequest(request);
var returnedException = result.Items["ERROR_EXCEPTION"] as RequestExecutionException;
// Then
returnedException.InnerException.ShouldBeSameAs(expectedException);
}
示例15: RealRun
/// <summary>
/// The method that performs the tests
/// Depending on the inputs different test code paths will be exercised
/// </summary>
internal void RealRun()
{
TaskScheduler tm = TaskScheduler.Default;
CreateTask(tm, _taskTree);
// wait the whole task tree to be created
_countdownEvent.Wait();
Stopwatch sw = Stopwatch.StartNew();
try
{
switch (_api)
{
case API.Cancel:
_taskTree.CancellationTokenSource.Cancel();
break;
case API.Wait:
switch (_waitBy)
{
case WaitBy.None:
_taskTree.Task.Wait();
_taskCompleted = true;
break;
case WaitBy.Millisecond:
_taskCompleted = _taskTree.Task.Wait(_waitTimeout);
break;
case WaitBy.TimeSpan:
_taskCompleted = _taskTree.Task.Wait(new TimeSpan(0, 0, 0, 0, _waitTimeout));
break;
}
break;
}
}
catch (AggregateException exp)
{
_caughtException = exp.Flatten();
}
finally
{
sw.Stop();
}
if (_waitTimeout != -1)
{
long delta = sw.ElapsedMilliseconds - ((long)_waitTimeout + s_deltaTimeOut);
if (delta > 0)
{
Debug.WriteLine("ElapsedMilliseconds way more than requested Timeout.");
Debug.WriteLine("WaitTime= {0} ms, ElapsedTime= {1} ms, Allowed Descrepancy = {2} ms", _waitTimeout, sw.ElapsedMilliseconds, s_deltaTimeOut);
Debug.WriteLine("Delta= {0} ms", delta);
}
else
{
var delaytask = Task.Delay((int)Math.Abs(delta)); // give delay to allow Context being collected before verification
delaytask.Wait();
}
}
Verify();
_countdownEvent.Dispose();
}