Created
November 28, 2013 12:09
-
-
Save RealyUniqueName/7690884 to your computer and use it in GitHub Desktop.
Simple exception class with stack information
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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