Try recompiling with and
without the - debug flag set, so you can see how the Exception class might function in a live project.
(continued)
199
Chapter 7: When Things Go Wrong
import Exception;
class ExceptionTest
{
public static function main()
{
try
{
throw new Exception( ???Some strange unknown error occurred??? );
}
catch( err : Exception )
{
trace( err.toString() );
}
}
}
When run successfully, you should be presented with the following output:
ExceptionTest.hx:13: Some strange unknown error occurred
File: ExceptionTest.hx | Line: 9
In method main of class ExceptionTest
StackTrace
===========
Called from ExceptionTest method main
CallStackTrace
===============
Called from Exception method new
Called from ExceptionTest method main
Summary
Although relatively short, you covered some very important topics in this chapter, including:
How to trace in each platform
How to modify the trace handler
How to use here and haxe.PosInfos for code tracking
How to use and handle exceptions
How to create your own exception framework
How to use the callStack() and exceptionStack() functions
The next chapter is the start of Part II of the book, where you learn how to use haXe and Neko to build
powerful web applications.
Pages:
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398