View source
class Exception
package haxe
extends NativeException
extended by Error, ValueException
Available on all platforms
Base class for exceptions.
If this class (or derivatives) is used to catch an exception, then
haxe.CallStack.exceptionStack()
will not return a stack for the exception
caught. Use haxe.Exception.stack
property instead:
try {
throwSomething();
} catch(e:Exception) {
trace(e.stack);
}
Custom exceptions should extend this class:
class MyException extends haxe.Exception {}
//...
throw new MyException('terrible exception');
haxe.Exception
is also a wildcard type to catch any exception:
try {
throw 'Catch me!';
} catch(e:haxe.Exception) {
trace(e.message); // Output: Catch me!
}
To rethrow an exception just throw it again. Haxe will try to rethrow an original native exception whenever possible.
try {
var a:Array<Int> = null;
a.push(1); // generates target-specific null-pointer exception
} catch(e:haxe.Exception) {
throw e; // rethrows native exception instead of haxe.Exception
}
Static methods
Constructor
new(message:String, ?previous:Exception, ?native:Any)
Create a new Exception instance.
The previous
argument could be used for exception chaining.
The native
argument is for internal usage only.
There is no need to provide native
argument manually and no need to keep it
upon extending haxe.Exception
unless you know what you're doing.