Prev | Current Page 366 | Next

L. McColl-Sylvester and F. Ponticelli

"Professional haXe and Neko"


Great, isn ??™ t it? The information presented is limited, but you ??™ ll look into extending this. The main point is
that you can now fire a complaint whenever certain criteria is not met, which can then be dealt with,
either at the end of the particular method, or by a class further down the object hierarchy.
Handling Different Exception Types
So, now you know how to throw and catch exceptions, but what use are they? Until this point, you have
been dealing specifically with thrown String exceptions, but you can ultimately throw any type of
object you like. What ??™ s more, you can specify different catch blocks for each type of exception that will
be thrown. For instance, within a try block, you might have two possible areas where an integer will be
189
Chapter 7: When Things Go Wrong
thrown and another three where a string will be thrown. Therefore, you can provide two catch blocks:
one for the thrown strings and one for the integers:
try
{
// ...
}
catch ( err : String )
{
trace( ???Error: ??? + err );
}
catch ( line : Int )
{
trace( ???Error found on line ??? + line );
}
If you happen to be unsure of what exception type might be thrown, or you want to provide a block of
code to handle all incoming exceptions, regardless of their type, then you can specify Dynamic as the
exception type.


Pages:
354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378