Пример #1
0
    /// <summary>
    /// Executes the chain of 'try-catch' wrappers.
    /// </summary>
    //[DebuggerStepThrough]
    public void Execute()
    {
        TryCatchBlock current = this.First;

        try
        {
            if (current.Action != null)
            {
                current.Action();
            }
        }
        catch (Exception exception)
        {
            while (current.Subsequent != null)
            {
                current = current.Subsequent;
                if (current.CanHandle(exception))
                {
                    current.Handle(exception);
                    break;
                }
                if (current.Subsequent == null)
                {
                    throw;
                }
            }
        }
        finally
        {
            while (current.Subsequent != null)
            {
                current = current.Subsequent;
                if (current.finalized && current.Action != null)
                {
                    current.Action();
                }
            }
        }
    }