Posts Tagged ‘super’

Throwing an error in a constructor before the super() statement

Friday, April 13th, 2012

I would have thought you could throw an error whenever you pleased like it, however the Flex compiler has some other ideas.

If you have a throw statement before the super() in the constructor, Flex will complain with the following error code:
1201: A super statement cannot occur after a this, super, return, or throw statement.

There is a workaround though, just wrap the throw statement in an anonymous function:

(function():void {
	throw new Error("Yay for workarounds!");
})();