Esempio n. 1
0
        /// <summary>
        /// Works like throwException(), except we search for the right try clause.
        /// </summary>
        public static void ThrowException( State state, object thrown )
        {
            Step tryStep = state.findAction( step => IsTryMarker( step ) );
            if( tryStep == null )
            {
            // Make sure we have a CoralException.
            if( !(thrown is CoralException) )
                thrown = new CoralException( thrown );

            CoralException cex = (CoralException)thrown;
            if( cex.trace == null )
                cex.setStackTrace( state );

            // Unwind everything else off the stack. There is an implicit "except" at the top anyway.
            state.clearActions();

            // Push on a thrower. We do this in a separate step so that the same try/catch can deal
            // with it at the Runner level.
            state.pushAction( new Step( null, a => { throw new UnhandledException( (CoralException)thrown ); }, "re-thrower" ) );
            return;
            }

            AstTry node = (AstTry)tryStep.node;
            node.throwException( state, thrown );
        }