本文整理汇总了C#中System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw方法的典型用法代码示例。如果您正苦于以下问题:C# ExceptionDispatchInfo.Throw方法的具体用法?C# ExceptionDispatchInfo.Throw怎么用?C# ExceptionDispatchInfo.Throw使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Runtime.ExceptionServices.ExceptionDispatchInfo
的用法示例。
在下文中一共展示了ExceptionDispatchInfo.Throw方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Throw
public void Throw(ExceptionDispatchInfo exceptionInfo)
{
Debug.Assert(exceptionInfo != null);
Thread thread = new Thread(() =>
{
exceptionInfo.Throw();
});
thread.Start();
thread.Join();
}
示例2: Scenario1
private static bool Scenario1()
{
s_EDI = null;
Console.WriteLine("\nScenario1");
Thread t1 = new Thread(new ThreadStart(ThrowEntryPoint));
t1.Start();
t1.Join();
bool fPassed = false;
if (s_EDI == null)
{
Console.WriteLine("s_EDI shouldn't be null!");
goto exit;
}
// ThrowAndCatch the exception
try
{
s_EDI.Throw();
}
catch(Exception ex)
{
string stackTrace = ex.StackTrace;
if (stackTrace.IndexOf("ThrowEntryPoint") == -1)
{
Console.WriteLine("FAILED - unable to find expected stackTrace");
}
else
{
Console.WriteLine("Caught: {0}", ex.ToString());
Console.WriteLine("Passed");
fPassed = true;
}
}
exit:
Console.WriteLine("");
return fPassed;
}
示例3: CheckRetryForExceptionAsync
private async Task CheckRetryForExceptionAsync(ExceptionDispatchInfo ex, bool reinitialize)
{
if (simulator.AsyncRetryHandler == null)
{
// Simply rethrow the exception.
ex.Throw();
}
else
{
// Need to release active keys etc.
CancelActiveInteractions();
bool result = await simulator.AsyncRetryHandler(ex);
if (!result)
throw new SimulatorCanceledException();
// When trying again, we need to re-initialize.
if (reinitialize)
await InitializeAsync();
}
}
示例4: StartSendAuthResetSignal
//
// This is to reset auth state on remote side.
// If this write succeeds we will allow auth retrying.
//
private void StartSendAuthResetSignal(ProtocolToken message, AsyncProtocolRequest asyncRequest, ExceptionDispatchInfo exception)
{
if (message == null || message.Size == 0)
{
//
// We don't have an alert to send so cannot retry and fail prematurely.
//
exception.Throw();
}
if (asyncRequest == null)
{
InnerStream.Write(message.Payload, 0, message.Size);
}
else
{
asyncRequest.AsyncState = exception;
IAsyncResult ar = InnerStreamAPM.BeginWrite(message.Payload, 0, message.Size, s_writeCallback, asyncRequest);
if (!ar.CompletedSynchronously)
{
return;
}
InnerStreamAPM.EndWrite(ar);
}
exception.Throw();
}
示例5: HandleException
/// <summary>
/// Provides specialized exception handling.
/// </summary>
/// <param name="capturedException">The captured exception</param>
private void HandleException(ExceptionDispatchInfo capturedException)
{
try
{
var errorResponseException = capturedException.SourceException as ErrorResponseMessageException;
if (errorResponseException != null)
{
this.ThrowTerminatingError(errorResponseException.ToErrorRecord());
}
var aggregateException = capturedException.SourceException as AggregateException;
if (aggregateException != null)
{
if (aggregateException.InnerExceptions.CoalesceEnumerable().Any() &&
aggregateException.InnerExceptions.Count == 1)
{
errorResponseException = aggregateException.InnerExceptions.Single() as ErrorResponseMessageException;
if (errorResponseException != null)
{
this.ThrowTerminatingError(errorResponseException.ToErrorRecord());
}
this.ThrowTerminatingError(aggregateException.InnerExceptions.Single().ToErrorRecord());
}
else
{
this.ThrowTerminatingError(aggregateException.ToErrorRecord());
}
}
capturedException.Throw();
}
finally
{
this.DisposeOfCancellationSource();
}
}
示例6: Rethrow
public static void Rethrow(ExceptionDispatchInfo nfo)
{
nfo.Throw ();
}
示例7: Scenario9
private static bool Scenario9()
{
s_EDI = null;
Console.WriteLine("\nScenario9");
Thread t1 = new Thread(new ThreadStart(ThrowEntryPoint));
t1.Start();
t1.Join();
bool fPassed = false;
if (s_EDI == null)
{
Console.WriteLine("s_EDI shouldn't be null!");
goto exit;
}
string s1 = null, s2 = null;
try
{
Scenario9Helper();
}
catch (Exception ex)
{
s1 = ex.ToString();
}
try
{
Console.WriteLine("Triggering 2nd Throw...");
s_EDI.Throw();
}
catch (Exception ex)
{
s2 = ex.ToString();
}
// S1 should have Scenario9HelperInner, Scenario9Helper and Scenario9 frames, in addition to the original frames.
// S2 should have Scenario9 frame, in addition to the original frames.
if ((s1.IndexOf("Scenario9HelperInner") == -1) || (s1.IndexOf("Scenario9Helper") == -1) ||
(s2.IndexOf("Scenario9HelperInner") != -1) || (s2.IndexOf("Scenario9Helper") != -1))
{
Console.WriteLine("S1: {0}\n", s1);
Console.WriteLine("S2: {0}", s2);
Console.WriteLine("FAILED");
}
else
{
Console.WriteLine("S1: {0}\n", s1);
Console.WriteLine("S2: {0}", s2);
Console.WriteLine("Passed");
fPassed = true;
}
exit:
Console.WriteLine("");
return fPassed;
}
示例8: Scenario4
private static bool Scenario4()
{
s_EDI = null;
Console.WriteLine("\nScenario4");
Thread t1 = new Thread(new ThreadStart(ThrowEntryPoint2));
t1.Start();
t1.Join();
bool fPassed = false;
if (s_EDI == null)
{
Console.WriteLine("s_EDI shouldn't be null!");
goto exit;
}
// ThrowCatchCreateEDI_ThrowEDICatch the exception on T1
// ThrowEDI on T2.
//
// We shouldn't see frames post ThrowEDI on T1 when we ThrowEDI on T2.
try
{
s_EDI.Throw();
}
catch (Exception ex)
{
string stackTrace = ex.StackTrace;
if ((stackTrace.IndexOf("ThrowEntryPointNestedHelper") == -1) ||
(stackTrace.IndexOf("Scenario4") == -1) ||
(stackTrace.IndexOf("ThrowEntryPoint2") != -1))
{
Console.WriteLine("FAILED - unable to find expected stackTrace");
}
else
{
Console.WriteLine("Caught: {0}", ex.ToString());
Console.WriteLine("Passed");
fPassed = true;
}
}
exit:
Console.WriteLine("");
return fPassed;
}
示例9: ThrowEntryPointNestedHelper
private static void ThrowEntryPointNestedHelper()
{
if (s_EDI == null)
{
try
{
ThrowEntryPointInner();
}
catch (Exception ex)
{
Console.WriteLine("Caught exception with message: {0}", ex.Message);
s_EDI = ExceptionDispatchInfo.Capture(ex);
}
// This will preserve the original throw stacktrace and
// commence a new one.
s_EDI.Throw();
}
else
{
Console.WriteLine("s_Exception is not null!");
s_EDI = null;
}
}