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); }
/// <summary> /// Visits the try statement tree. /// </summary> /// <param name="tryExpr"></param> public void Try(TryCatchExpr tryExpr) { _callBack(tryExpr); foreach (var stmt in tryExpr.Statements) { Visit(stmt); } Visit(tryExpr.Catch); }
/// <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); }
/// <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); }
/// <summary> /// try/catch. /// </summary> /// <returns></returns> public override Expr Parse() { var stmt = new TryCatchExpr(); var statements = new List<Expr>(); _tokenIt.Expect(Tokens.Try); ParseBlock(stmt); _tokenIt.AdvancePastNewLines(); _tokenIt.ExpectMany(Tokens.Catch, Tokens.LeftParenthesis); stmt.ErrorName = _tokenIt.ExpectId(); _tokenIt.Expect(Tokens.RightParenthesis); ParseBlock(stmt.Catch); stmt.Ctx = Ctx; stmt.Catch.Ctx = Ctx; return stmt; }
/// <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; }