Exception handling
Exceptions are messages passed from the inner call of your program to the outer call (it is going through the stack from the most recent call to the older one). In haXe, any object can be thrown as an exception. Exception handling (that is intercepting those messages) is done with the help of the
try
and catch
keywords.
try { doSomething(); } catch (e : Int) { //If do something throws an Int this block of code will be executed. } catch (e : String) { //If do something throws a String this block of code will be executed. } catch (e : Dynamic) { //If do something throws something else this block of code will be executed. }
As you can see in this example, you can specify different types of exceptions to intercept and execute different blocks of code according to these types. The Dynamic
type allows you to intercept any type of exception that hasn't been intercepted before. Mind the order in which you write your blocks, as they are evaluated from top to bottom...