Handle this typehints
[hiphop-php.git] / hphp / test / quick / exceptions.php
blobe9e702a78556c3e6d5ff6aefcb11bb9584adc22a
1 <?hh
3 class Ex1 extends Exception {
6 class Ex2 extends Exception {
9 class Ex3 extends Exception {
12 function bar($a) {
13 print "bar $a\n";
14 $b = array(1, 2);
15 foreach($b as $c) {
16 if ($a == 0) {
17 throw new Ex1();
18 } else if ($a == 2) {
19 throw new Ex2();
20 } else if ($a == 3) {
21 throw new Ex3();
26 function foo2($a) {
27 try {
28 call_user_func("bar", $a);
29 } catch (Ex1 $e) {
30 print "caught 1\n";
34 function foo1($a) {
35 foo2($a);
38 function foo($a) {
39 foo1($a);
42 function main1() {
43 $a = array(0, 1, 2);
44 $b = array(0);
46 foreach ($b as $c) {
47 try {
48 array_map("foo", $a);
49 } catch (Ex2 $e) {
50 print "caught 2\n";
54 try {
55 foreach (array(1,2,3) as $_) {
56 echo "before\n";
57 throw new Exception();
58 echo "after\n";
60 } catch (Exception $e) {
61 echo "caught\n";
64 main1();
66 class A {
67 function __construct() {
68 throw new Exception();
72 function main2() {
73 try {
74 call_user_func("hphp_create_object", "A", NULL);
75 } catch (Exception $e) {
76 print "caught exception\n";
79 main2();
81 class Ex4 extends Ex3 {
82 function __construct($s) {
83 var_dump($s);
84 var_dump($this->getTraceAsString());
87 function a() {
88 return b();
90 function b() {
91 return c();
93 function c() {
94 $e = new Exception();
95 var_dump($e->getTraceAsString());
96 return new Ex4('hello, exception');
98 function main3() {
99 $e = a();
100 printf("Exception from %s:%d\n", $e->getFile(), $e->getLine());
101 var_dump($e->getTraceAsString());
103 $b = array(3);
104 try {
105 array_map("foo", $b);
106 } catch (Ex3 $e) {
107 print "caught 3\n";
108 throw $e;
111 main3();