OpenFL UncaughtErrorEvent can be cached only in main app class?

Added loaderInfo.uncaughtErrorEvents.addEventListener(UncaughtErrorEvent.UNCAUGHT_ERROR, onError); to Main app class.
If I call throw"ERROR!"); in Main class, handler invoked.
But if I call throw"ERROR!"); in any other (not displayobject) class, handler hasn’t been invoked.

I believe we try/catch around every event dispatch from the stage, so if you throw the error in Event.ENTER_FRAME code I believe it will work, but I’m not sure it will work if you throw it from a Haxe timer (for example)

Well it doesn’t work as expected (like it worked in Flash for ex).
handler is not beinge invoked, however I can see error in console.
I’ll try to add some example later.

Simple sample on document class

        loaderInfo.uncaughtErrorEvents.addEventListener(UncaughtErrorEvent.UNCAUGHT_ERROR, onError);

		openfl.Lib.application.window.stage.addEventListener(, e -> {
			var a:Dynamic = null;
			a.b = 1;


        private function onError(event:UncaughtErrorEvent):Void

@singmajesty I’ve created another simple sample, that doesn’t work. Can you help me please?

class Main extends openfl.display.Sprite
	public function new()

		loaderInfo.uncaughtErrorEvents.addEventListener(, handleUncaughtError);
		stage.addEventListener(, event -> throw new openfl.errors.Error("ERROR!"));

	private function handleUncaughtError(

Using temporary workaround for HTML5 target:

js.Browser.window.onerror = function(msg, url, line, col, error) {
	// Note that col & error are new to the HTML 5 spec and may not be
	// supported in every browser.  It worked for me in Chrome.
	var extra = (col == 0 ? '' : '\ncolumn: ' + col);
	untyped extra += !error ? '' : '\nerror: ' + error.stack;

	// You can view the information in an alert to see things working like this:
	js.Browser.alert("Error: " + msg + "\nurl: " + url + "\nline: " + line + extra);

	var suppressErrorAlert = true;
	// If you return true, then error alerts (like in older versions of
	// Internet Explorer) will be suppressed.
	return suppressErrorAlert;

Another solution:

var captureStack = (cast js.lib.Error).captureStackTrace;
(cast js.lib.Error).captureStackTrace = function(a, b):Void
	captureStack(a, b);
1 Like