ActionStep supports exceptions through the following classes:
This document explain how this is done.
Please note that from now onwards, trace refers to ASDebugger.trace, or any other ASDebugger trace functions. You can do this by compiling with mtasc and using the -trace switch. For example,
-trace org.actionstep.ASDebugger.trace
This compiler will automatically pass information such as line number, class, file to a trace function. ActionStep takes advantage of this information and stores it. Look at this call stack:
trace(object)ASDebugger::trace(object, level, klass, file, line)NSException::addReference(klass, file, line)References, which contain file, line, etc, are added to an array, which will be displayed in a Java-like style, eg:
[DEBUG] NSException(
ASInvalidCondition:
index is funny,
null
)
at org.actionstep.NSArray.replaceObjectAtIndexWithObject(NSArray.as:634)
at org.actionstep.remoting.ASRecordSet.replaceRecordAtIndex(ASRecordSet.as:207)
at org.actionstep.remoting.ASRecordSet.initWithResponseForService(ASRecordSet.as:132)
NSException extends Flash’s native Error class, and as such contains the familiar property message.
However, Error is unable to list debug stuff like the line number, file, etc.
NSException can capture these information as described in mtasc.
Use the description method to format the exception as also seen in mtasc.
NSException also has the userInfo property, which is an NSDictionary that contains context info, and will be traced if either the toString or description method is invoked. This is in compliance with Cocoa’s specifications.
NSException supports the use of inner exceptions, using the following methods:
exceptionWithNameReasonInnerExceptionUserInfo(name:String, reason:String, exception:NSException, userInfo:NSDictionary):NSExceptioninitWithNameReasonInnerExceptionUserInfo(name:String, reason:String, exception:NSException, userInfo:NSDictionary):NSException
You can use inner exceptions if Exception X is thrown as a result handling Exception Y in a catch block.
ASDebugger’s trace functions call a helper function, processTrace to provide exceptions with reference information.
Passing an instance of NSException to trace causes this to occur.
This is in contrast with Flash, where toString is invoked. You have to manually invoke toString or description yourself if you want to print out the description.
For example:
//no output trace(myException); //this has trace(myException.toString()); //as well as this trace(myException.description()); //and this too trace(myException.message);