Esempio n. 1
0
        public void Rethrow()
        {
            var src = @"
try
    1 / 0
catch ex:DivisionByZeroException
    throw";

            var result = Expr.Try(
                Expr.Block(
                    Expr.Div(Expr.Int(1), Expr.Int(0))
                    ),
                Expr.Catch(
                    "DivisionByZeroException",
                    "ex",
                    Expr.Block(Expr.Throw())
                    )
                );

            TestParser(src, result);
        }
Esempio n. 2
0
        public void MultipleCatch()
        {
            var src = @"
try
    1 / 0
catch ex:DivisionByZeroException
    log ex
catch
    doStuff ()
    log ""whoopsie""
finally
    log ""finally""
";

            var result = Expr.Try(
                Expr.Block(
                    Expr.Div(Expr.Int(1), Expr.Int(0))
                    ),
                Expr.Block(
                    Expr.Invoke("log", Expr.Str("finally"))
                    ),
                Expr.Catch(
                    "DivisionByZeroException",
                    "ex",
                    Expr.Block(
                        Expr.Invoke("log", Expr.Get("ex"))
                        )
                    ),
                Expr.CatchAll(
                    Expr.Invoke("doStuff", Expr.Unit()),
                    Expr.Invoke("log", Expr.Str("whoopsie"))
                    )
                );

            TestParser(src, result);
        }
Esempio n. 3
0
        public void SingleCatch()
        {
            var src = @"
try
    1 / 0
catch ex:DivisionByZeroException
    log ex
";

            var result = Expr.Try(
                Expr.Block(
                    Expr.Div(Expr.Int(1), Expr.Int(0))
                    ),
                Expr.Catch(
                    "DivisionByZeroException",
                    "ex",
                    Expr.Block(
                        Expr.Invoke("log", Expr.Get("ex"))
                        )
                    )
                );

            TestParser(src, result);
        }