You are here: Recent News » Projects » ActionStep » ActionStep Features » Exceptions

 

Exceptions

ActionStep supports exceptions through the following classes:

  1. org.actionstep.NSException
  2. org.actionstep.ASDebugger

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

mtasc

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:

  1. trace(object)
  2. ASDebugger::trace(object, level, klass, file, line)
  3. 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

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.

Inner exceptions

NSException supports the use of inner exceptions, using the following methods:

  • +exceptionWithNameReasonInnerExceptionUserInfo(name:String, reason:String, exception:NSException, userInfo:NSDictionary):NSException
  • -initWithNameReasonInnerExceptionUserInfo(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

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);

projects/actionstep/documentation/exceptions.txt · Last modified: 2007/02/19 08:17 by niko