peelonet/tempearly — pull request #87 by RauliL (2014-11-20 21:50:39+00:00)
Title: Add support for try statement.

1. Modifies `Interpreter` class so that caught and uncaught exceptions
are stored as `Value` instances, instead of `ExceptionObject`. This
gives us more flexibility with AST.
2. Adds support for `try` statement which can be used to catch
exceptions thrown either by API methods or `throw` statement.

`try` statement has following kind of syntax:

```
try:
throw Exception("this is exception message");
catch Exception ex:
response.write("Exception caught: " + ex.message);
else:
response.write("No exception was thrown.");
finally:
response.write("This is always executed.")
end try;
```

There can be more than one `catch` statement to catch various kinds
of exceptions. `catch` statements can also be completely omitted if
an `else` or `finally` statement is provided.

`catch` statements take an optional type and variable. Type is an
type hint (the kind that is used in function parameters), thus it
allows you to catch multiple kinds of exceptions with syntax like
`IOError|TypeError|LookupError`. Type can also be omitted, in which
case every kind of exception is caught. Variable can also be omitted.

`try` statement can also have an `else` substatement, which is
executed only if no exception was thrown in body of the `try`
statement. This is ripped off from Python and is very handy
sometimes.

If `try` statement has an `finally` substatement, then that statement
is always executed, no matter what happens. It is also kinda
dangerous thing to have, if `finally` statement throws an exception
things can go completely bonk with the interpreter, althought it
doesn't crash or anything.