当前位置: 首页>>代码示例>>C#>>正文


C# ExceptionDispatchInfo.Throw方法代码示例

本文整理汇总了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();
        }
开发者ID:rafaelmtz,项目名称:azure-webjobs-sdk,代码行数:11,代码来源:BackgroundExceptionDispatcher.cs

示例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;
    }
开发者ID:CheneyWu,项目名称:coreclr,代码行数:39,代码来源:StackTracePreserveTests.cs

示例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();
            }
        }
开发者ID:kpreisser,项目名称:MouseClickSimulator,代码行数:21,代码来源:StandardInteractionProvider.cs

示例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();
        }
开发者ID:eerhardt,项目名称:corefx,代码行数:31,代码来源:SslState.cs

示例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();
            }
        }
开发者ID:FrankSiegemund,项目名称:azure-powershell,代码行数:41,代码来源:ResourceManagerCmdletBase.cs

示例6: Rethrow

 public static void Rethrow(ExceptionDispatchInfo nfo)
 {
     nfo.Throw ();
 }
开发者ID:rdterner,项目名称:MonoLib,代码行数:4,代码来源:ExceptionTests.cs

示例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;
    }
开发者ID:CheneyWu,项目名称:coreclr,代码行数:58,代码来源:StackTracePreserveTests.cs

示例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;
    }
开发者ID:CheneyWu,项目名称:coreclr,代码行数:45,代码来源:StackTracePreserveTests.cs

示例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;
        }
    }
开发者ID:CheneyWu,项目名称:coreclr,代码行数:24,代码来源:StackTracePreserveTests.cs


注:本文中的System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。