Reputation: 321
Hypothetically, I have a switch that has 437 cases. I've identified every possible case (I think), and each is handled.
I'm worried that I missed # 438, and want something in the Default to alert me of this.
I could put a
trace("ERROR! Stackoverflow has detected your ginormous gaffe and suspended your account indefinitely!");
in there, but I'm worried that this error will occur 7 weeks from now and the trace will be lost among all of my other silly warning traces. I've considered having my Default do this:
trace(myArray[-1]);
which would surely(?) give an error and stop the program, alerting me to my hideous oversight, but am wondering if there isn't some better, smarter way to go about detecting a possible error like this.
Anyone? Bueller?
Upvotes: 2
Views: 165
Reputation: 300
The first option is to throw an exception:
throw new Error('Exception!!!')
but you wont get anything if you don't have debugger flashplayer
Another way is to show a popup: In case you use flashplayer in browser:
ExternalInterface.call("alert", "Exception!!!");
In case you use Flex Framework:
Alert.show('Exception!!!')
You could try to highlite it somehow:
trace( "==========================================\n" +
"==========================================\n" +
"==========================================\n" +
"===============Exception!!!===============\n" +
"==========================================\n" +
"==========================================\n" +
"==========================================\n" +);
And the last option is a custom popup:
import flash.text.TextField;
import flash.text.TextFieldAutoSize;
const theStage:Stage = MovieClip(root).stage;
const tf:TextField = new TextField();
tf.text = "Exception!!!";
tf.autoSize = TextFieldAutoSize.LEFT;
tf.x = theStage.stageWidth - tf.width >> 1;
tf.y = theStage.stageHeight - tf.height >> 1;
tf.border = true;
tf.addEventListener(MouseEvent.CLICK, function(e:MouseEvent){
e.currentTarget.parent.removeChild(e.currentTarget);
})
theStage.addChild(tf);
Upvotes: 3
Reputation: 865
Why not to throw an error?
default:
throw new Error("Default reached");
Upvotes: 5