[FP10.1] Global Error Handler
/**
* Copyright clockmaker ( http://wonderfl.net/user/clockmaker )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/gmBj
*/
package {
import com.bit101.components.*;
import flash.display.*;
import flash.events.*;
public class Main extends Sprite {
public function Main() {
new PushButton(this, 100, 40, "throw new Error", _onBtnClick);
_radio1 = new RadioButton(this, 100, 90, "UNCAUGHT_ERROR Handler ON", true, _onChange);
_radio2 = new RadioButton(this, 100, 120, "UNCAUGHT_ERROR Handler OFF", false, _onChange);
_label = new TextArea(this, 100, 170, "");
loaderInfo.uncaughtErrorEvents.addEventListener(UncaughtErrorEvent.UNCAUGHT_ERROR, _onUncaughtError);
}
private var _label:TextArea;
private var _radio1:RadioButton;
private var _radio2:RadioButton;
private function _onChange(e:Event):void {
if (_radio1.selected)
loaderInfo.uncaughtErrorEvents.addEventListener(UncaughtErrorEvent.UNCAUGHT_ERROR, _onUncaughtError);
else
loaderInfo.uncaughtErrorEvents.removeEventListener(UncaughtErrorEvent.UNCAUGHT_ERROR, _onUncaughtError);
_label.text = "";
}
private function _onBtnClick(e:MouseEvent):void {
throw new Error("This is Custom Error No." + (1000 * Math.random() >> 0));
}
private function _onUncaughtError(event:UncaughtErrorEvent):void {
_label.text = event.error;
event.preventDefault(); // ココ重要!
}
}
}