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.

A message that's not handled at any point in your program may cause the program to exit abruptly, so you should pay attention to these.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.117.230.81