Skip to content

Instantly share code, notes, and snippets.

@RealyUniqueName
Created November 28, 2013 12:09
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RealyUniqueName/7690884 to your computer and use it in GitHub Desktop.
Save RealyUniqueName/7690884 to your computer and use it in GitHub Desktop.
Simple exception class with stack information
package fst.exception;
import haxe.CallStack;
/**
* Exceptions base
*
*/
class Exception {
/** Exception message */
public var message (default,null) : String;
/** Call stack of this exception */
public var stack (default,null) : Array<StackItem>;
/**
* Constructor
*
* @param message
* @param shiftStack - wich callstack entry to use relative to position where exception is thrown
* If shiftStack == 1, exception will point to the the call of a method within
* which exception was thrown
*/
public function new (message:String, shiftStack:Int = 0) : Void {
this.message = message;
this.stack = CallStack.callStack();
this.stack.splice(-4, 4 - shiftStack);
// this.stack.pop();
}//function new()
/**
* Convert exception to string
*
*/
public function toString () : String {
return '<' + Type.getClassName(Type.getClass(this)) + '>: ' + this.message + CallStack.toString(this.stack);
}//function toString()
}//class Exception
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment