Prev | Current Page 371 | Next

L. McColl-Sylvester and F. Ponticelli

"Professional haXe and Neko"

The main purpose for catching exceptions is to
provide code for certain eventualities that the main body of code was not designed to handle. This could
be handled in a parent class, or within the method of the exceptions inception. However, all exceptions
should at least be expected to some extent. For example, while dealing with files, you should expect the
occasional file not found or permission denied errors. Thus, by providing catch statements, you are able
to deal with these eventualities. However, should a completely unexpected error occur in an unexpected
place, you should at least be able to save what work you can, clean up as many objects as possible, and
prepare for the worst. Luckily, haXe provides a means to do just that, albeit only for Flash and JavaScript,
using flash.Lib.setErrorHandler and js.Lib.setErrorHandler .
static function globalHandler( msg : String, stack : Array < String > )
{
trace( ???Error : ??? + msg );
}
static function main()
{
flash.Lib.setErrorHandler( globalHandler );
throw ???Some error???;
}
A setErrorHandler() method was deliberately excluded from the Neko library as Neko controls the
event loop itself, so you are always in a subcall of main .


Pages:
359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383