Prev | Current Page 365 | Next

L. McColl-Sylvester and F. Ponticelli

"Professional haXe and Neko"

You simply use the throw keyword, followed by the information to throw:
throw ???Catch this!???;
Simple, huh? Now you just need to tackle when to throw it. You can ??™ t just throw them willy - nilly, as
you ??™ ll end up causing unnecessary panic. However, by not throwing an exception, you may be
withholding valuable information that other classes will rely on. So, what do you do?
The answer is often down to personal preference. Usually, the best course of action is first to decide
on the urgency of the error at hand, then, if there is absolutely no way for the current function to deal
with the issue and the process requested is of an urgent nature, then an exception must be thrown. But,
in order to do that, you will need to find out if an error is present, which requires data checking. Take a
look at the CaughtException class using the throw keyword:
class CaughtExceptionB
{
public static function main()
{
try
{
var t : Array < String > ;
if (t != null)
t.push(???me???);
else
throw ???Array t is not an object???;
}
catch ( err : String )
{
trace( err );
}
}
}
Now, if you compile and run this class in Flash, you should finally see your exception printed to screen.


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