langur exceptions

An exception in langur is always a hash that is guaranteed to contain certain fields, even if they are empty. You may include other fields in a hash that you throw. You can also throw anything else and it becomes the required hash.

exception hash

Any exception hash is guaranteed to contain the following fields.

"cat" an exception general category
"msg" the message
"src" exception source
"hst" previous exception or null

catching exceptions

... catch [.err] { ... }

There is no explicit try block. All the statements preceding a catch within a block are the implicit try block. You could put a catch at the end of your script and to cover the entire script.

If an exception variable is not specified, it is implicitly .err.

If a catch is embedded within a catch, they cannot each use the same exception variable name.

If a single expression is used and does not start with a variable name, curly brackets are not required on the catch expression.

If you do not rethrow an exception, it is not propogated past the catch.

catch exception example

123 / 0 catch if .err["cat"] == "math" { 456 } else { 890 } # result == 456