Throw() public méthode

public Throw ( ) : void
Résultat void
        public void Throw(ExceptionDispatchInfo exceptionInfo)
        {
            Debug.Assert(exceptionInfo != null);

            Thread thread = new Thread(() =>
            {
                exceptionInfo.Throw();
            });
            thread.Start();
            thread.Join();
        }
    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;
    }
        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();
            }
        }
Exemple #4
0
        //
        //  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();
        }
        /// <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();
            }
        }
Exemple #6
0
 public static void Rethrow(ExceptionDispatchInfo nfo)
 {
     nfo.Throw ();
 }
    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;
    }
    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;
    }
    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;
        }
    }