added more test cases
[swftools.git] / lib / as3 / ok / trycatch.as
1 package {
2     import flash.display.MovieClip;
3     import flash.net.navigateToURL;
4
5     public class MyError {
6     }
7     public class MyOtherError {
8         var ok5="ok 5/7";
9     }
10     public class ClassWithStaticFunctions {
11         static function ok7() {
12             trace("ok 7/7");
13         }
14     }
15     public class Main extends flash.display.MovieClip {
16
17         public function getClass():Class {
18             return ClassWithStaticFunctions;
19         }
20                 
21         public function checkScope():void
22         {
23             try {
24                 flash.net.navigateToURL;
25             } catch (e:Error) {
26             }
27             trace("ok 6/7");
28
29             with(getClass()) {
30                 try {
31                   throw new Error;
32                 } catch(e:Error) {
33                     ok7();
34                 }
35             }
36         }
37                 
38
39         function Main() {
40             try {
41                 throw new MyError
42                 trace("error");
43             } catch(error:Error) {
44                 // MyError is not of the Error class
45                 trace("error");
46             } catch(error:MyError) {
47                 trace("ok 1/7");
48             } catch(x) {
49                 trace("error");
50             }
51             
52             try {
53                 throw new MyOtherError
54                 trace("error");
55             } catch(error:MyError) {
56                 trace("error");
57             } catch(x:*) { // ":*" is the same as ""
58                 trace("ok 2/7");
59             }
60             
61             try {
62                 trace("ok 3/7");
63                 // don't throw any error
64             } catch(error:MyError) {
65                 trace("error");
66             } catch(error:MyOtherError) {
67                 trace("error");
68             } catch(x:*) { // ":*" is the same as ""
69                 trace("error");
70             }
71
72             trace("ok 4/7");
73
74             try {throw new MyOtherError} 
75             catch(x:*) {
76                 trace((x as MyOtherError).ok5);
77             }
78
79             checkScope();
80             
81             trace("[exit]");
82         }
83     }
84 }