I’m trying to write some code to catch all Errors and ErrorEvents however i cant seem to get it working for thrown Errors, only ErrorEvents.
The following works fine
package
{
import flash.display.Sprite;
import flash.events.ErrorEvent;
import flash.events.UncaughtErrorEvent;
public class Main extends Sprite
{
public function Main():void
{
loaderInfo.uncaughtErrorEvents.addEventListener(UncaughtErrorEvent.UNCAUGHT_ERROR, onUncaughtError);
dispatchEvent(new ErrorEvent(ErrorEvent.ERROR));
}
private function onUncaughtError(e:UncaughtErrorEvent):void
{
trace( "Main.onUncaughtError > e : " + e );
e.preventDefault();
}
}
}
But this does not catch the error, and results int the standard debug player error popup.
package
{
import flash.display.Sprite;
import flash.events.UncaughtErrorEvent;
public class Main extends Sprite
{
public function Main():void
{
loaderInfo.uncaughtErrorEvents.addEventListener(UncaughtErrorEvent.UNCAUGHT_ERROR, onUncaughtError);
throw new Error();
}
private function onUncaughtError(e:UncaughtErrorEvent):void
{
trace( "Main.onUncaughtError > e : " + e );
e.preventDefault();
}
}
}
This is happening in all supported players 10.1 and up.
Ok solved it. The code does work, but it’s still triggering the debugger in the IDE.
Hitting continue will then execute the handler code, and if you run the swf separately from the IDE it’s fine.