Пример #1
0
		public Expr OnParseTryCatch()
		{
            var tokenIt = this._parser.TokenIt;
            var initiatorToken = tokenIt.NextToken;
			var expr = new TryCatchExpr();
			// <codeTryCatch>

            // Try
            tokenIt.Expect(Tokens.Try);
            expr.Statements = new List<Expr>();
            this.ParseBlock(expr);
            tokenIt.AdvancePastNewLines();

            // Catch
            var catchToken = tokenIt.NextToken;
            tokenIt.ExpectMany(Tokens.Catch, Tokens.LeftParenthesis);
            expr.ErrorName = tokenIt.ExpectId();
            tokenIt.Expect(Tokens.RightParenthesis);
            expr.Catch = new BlockExpr();
            this.ParseBlock(expr.Catch);
            this._parser.SetupContext(expr.Catch, catchToken);
            
            // </codeTryCatch>
			this._parser.SetupContext(expr, initiatorToken);
			return expr;
		}
Пример #2
0
        /// <summary>
        /// Execute
        /// </summary>
        public object VisitTryCatch(TryCatchExpr expr)
        {
            var tryScopePopped = false;
            var catchScopePopped = false;
            try
            {
                this.Ctx.Memory.Push();
                LangHelper.Evaluate(expr.Statements, expr, this);
                this.Ctx.Memory.Pop();
                tryScopePopped = true;
            }
            // Force the langlimit excpetion to propegate 
            // do not allow to flow through to the catch all "Exception ex".
            catch (LangLimitException)
            {
                throw;
            }
            catch (LangFailException)
            {
                throw;
            }
            catch (Exception ex)
            {
                this.Ctx.Limits.CheckExceptions(expr);

                // Pop the try scope.
                if (!tryScopePopped) this.Ctx.Memory.Pop();

                // Push the scope in the catch block
                this.Ctx.Memory.Push();
                var lException = LangTypeHelper.ConvertToLangClass(LError.FromException(ex));
                this.Ctx.Memory.SetValue(expr.ErrorName, lException);

                // Run statements in catch block.
                if (expr.Catch != null && expr.Catch.Statements.Count > 0)
                    LangHelper.Evaluate(expr.Catch.Statements, expr.Catch, this);

                // Pop the catch scope.
                this.Ctx.Memory.Pop();
                catchScopePopped = true;
            }
            finally
            {
                // Pop the catch scope in case there was an error.
                if (!catchScopePopped) this.Ctx.Memory.Remove(expr.ErrorName);
            }
            return LObjects.Null;
        }
Пример #3
0
 /// <summary>
 /// Visits the try statement tree.
 /// </summary>
 /// <param name="tryExpr"></param>
 public object VisitTryCatch(TryCatchExpr expr)
 {
     _callBackOnNodeStart(expr);
     foreach (var stmt in expr.Statements)
     {
         stmt.Visit(this);
     }
     foreach (var stmt in expr.Catch.Statements)
     {
         stmt.Visit(this);
     }
     return null;
 }