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 ...

Get haXe 2 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.