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

staticcaught(value:Any):Exception

Available on unity

staticthrown(value:Any):Any

Available on unity

Constructor

@:has_untypednew(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.

Variables

read onlystack:CallStack

Available on clay web

The call stack at the moment of the exception creation.

read onlynative:Any

Available on clay web

Native exception, which caused this exception.

read onlymessage:String

Available with clay native, gif plugin, headless, tilemap plugin, unity

Exception message.

Methods

toString():String

Available with clay native, gif plugin, headless, tilemap plugin, unity

Returns exception message.

unwrap():Any

Available on unity