5.16 try/catch

Haxe allows catching values using its try/catch syntax:

try try-expr
catch (varName1:Type1) catch-expr-1
catch (varName2:Type2) catch-expr-2

If during runtime the evaluation of try-expression causes a throw, it can be caught by any subsequent catch block. These blocks consist of

  • a variable name which holds the thrown value,
  • an explicit type annotation which determines which types of values to catch, and
  • the expression to execute in that case.

Haxe allows throwing and catching any kind of value, it is not limited to types inheriting from a specific exception or error class. Catch blocks are checked from top to bottom with the first one whose type is compatible with the thrown value being picked.

This process has many similarities to the compile-time unification behavior. However, since the check has to be done at runtime there are several restrictions: