throw で条件分岐
おもしろい。
/**
* Copyright bkzen ( http://wonderfl.net/user/bkzen )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/gNSC
*/
package
{
import flash.events.Event;
import flash.events.MouseEvent;
import com.actionscriptbible.Example;
/**
* throw 式条件分岐
* @author jc at bkzen
*/
public class Test90 extends Example
{
private var cnt: uint;
public function Test90()
{
if (stage) init();
else addEventListener(Event.ADDED_TO_STAGE, init);
}
private function init(e: Event = null): void
{
removeEventListener(Event.ADDED_TO_STAGE, init);
//
trace("click");
stage.addEventListener(MouseEvent.CLICK, onClick);
}
private function onClick(e:MouseEvent):void
{
try { foo(); }
catch (str: String) { trace("String ", str); }
catch (i: int) { trace("int", i); }
catch (err: Error) { trace("Error", err); }
catch (c: Class) { trace("Class", c); }
catch (o: Object) { trace("Object", o); }
}
private function foo():void
{
switch (cnt++%5)
{
case 0:
throw { "toString": function(): String { return "[MyObject]" }};
break;
case 1:
throw "'Error'";
break;
case 2:
throw 1234;
break;
case 3:
throw new Error("new Error");
break;
case 4:
throw Class;
break;
}
}
}
}