/// <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);
        }
Exemple #2
0
        /// <summary>
        /// Execute
        /// </summary>
        public override object DoEvaluate()
        {
            bool tryScopePopped   = false;
            bool catchScopePopped = false;

            try
            {
                Ctx.Memory.Push();
                LangHelper.Evaluate(_statements, 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)
            {
                Ctx.Limits.CheckExceptions(this);

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

                // Push the scope in the catch block
                Ctx.Memory.Push();
                Ctx.Memory.SetValue(ErrorName, new LClass(LError.FromException(ex)));

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

                // Pop the catch scope.
                Ctx.Memory.Pop();
                catchScopePopped = true;
            }
            finally
            {
                // Pop the catch scope in case there was an error.
                if (!catchScopePopped)
                {
                    Ctx.Memory.Remove(ErrorName);
                }
            }
            return(LObjects.Null);
        }