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
}

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 onlymessage:String

Exception message.

read onlynative:Any

Native exception, which caused this exception.

read onlyprevious:Null<Exception>

Contains an exception, which was passed to previous constructor argument.

read onlystack:CallStack

The call stack at the moment of the exception creation.

Methods

details():String

Detailed exception description.

Includes message, stack and the chain of previous exceptions (if set).

toString():String

Returns exception message.