Exemplo n.º 1
0
//-----------------------------------------------------------------------------
// Parse a try-catch-finally statement
// -> 'try' block 'finally' block
// -> 'try' block <'catch' '(' TypeSig id ')' block>+ ['finally' block]?
//-----------------------------------------------------------------------------
    protected TryStatement ParseTryCatchFinallyStatement()
    {
        ReadExpectedToken(Token.Type.cTry);
        
        BlockStatement stmtTry = ParseStatementBlock();
        
        Token t2 = m_lexer.PeekNextToken();
        ArrayList a = new ArrayList();
        while(t2.TokenType == Token.Type.cCatch)
        {            
            CatchHandler c = ParseCatchHandler();
            a.Add(c);
            t2 = m_lexer.PeekNextToken();
        }
        
        CatchHandler [] arCatch = new CatchHandler[a.Count];
        for(int i = 0; i < a.Count; i++) 
            arCatch[i] = (CatchHandler) a[i];
        
        BlockStatement stmtFinally = null;
        if (t2.TokenType == Token.Type.cFinally)
        {
            ConsumeNextToken();
            stmtFinally = ParseStatementBlock();            
        }
        
        return new TryStatement(stmtTry, arCatch, stmtFinally);
    }
Exemplo n.º 2
0
// Must have a finally or at least one Catch (or both)
    public TryStatement(
        BlockStatement stmtTry,     // never null
        CatchHandler [] arCatch,    // can be null
        BlockStatement stmtFinally  // can be null        
    )
    {
        Debug.Assert(stmtTry != null); // always have a try block        
        Debug.Assert((arCatch != null && arCatch.Length > 0) || stmtFinally != null);
                
        m_stmtTry = stmtTry;
        m_arCatchHandlers = (arCatch == null) ? new CatchHandler[0] : arCatch;        
        m_stmtFinally = stmtFinally;
        
        // @todo - this is wrong
        m_filerange = stmtTry.Location;
    }