Throw an Error!

by rfkrocktk
♥0 | Line 35 | Modified 2010-10-08 01:59:27 | MIT License
play

ActionScript3 source code

/**
 * Copyright rfkrocktk ( http://wonderfl.net/user/rfkrocktk )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/2WGg
 */

package {
    import flash.text.TextFormat;
    import flash.text.TextField;
    import flash.display.StageScaleMode;
    import flash.display.StageAlign;
    import flash.display.Sprite;
    import flash.utils.getDefinitionByName;
    
    public class ThrowError extends Sprite {
        
        public function ThrowError() {
            this.stage.align = StageAlign.TOP_LEFT;
            this.stage.scaleMode = StageScaleMode.NO_SCALE;
            
            var textfield:TextField = new TextField();
            textfield.x = textfield.y = 10;
            textfield.width = stage.stageWidth - 20;
            textfield.height = stage.stageHeight - 20;
            textfield.defaultTextFormat = new TextFormat("Courier New");
            
            this.addChild(textfield);
            
            textfield.appendText("Generating Stacktrace: \n");
            textfield.appendText(new MethodCaller().callMethod(getStackTrace));
        }
        
        private function getStackTrace():String {
            try {
                getDefinitionByName("NONEXISTENTDEFINITION");
            } catch (e:Error) {
                return e.getStackTrace();
            }

            return null;
        }

    }
}

class MethodCaller {
    
    public function callMethod(func:Function):String {
        return func.apply(this);
    }

}