PhpTryCatch exception test. Use c1 of c in trycatch, b1 of B in c1, and a1 of a in b1. The default value is: a1 throws an exception, b1 captures the a1 exception, and then throws the exception. c1 captures the exception, and uses c1 of c in try catch on the page, use b1 of B in c1 and a1 of a in b1.
The default value is: a1 throws an exception, b1 captures the a1 exception, and then throws the exception, c1 captures the exception, and then throws the exception. Finally, the page captures and outputs the exception.
The result is:
X-Powered-By: PHP/5.1.1
Content-type: text/html
#0 D: \ workspace \ myzCollection \ test. php (16): a-> a1 ()
#1 D: \ workspace \ myzCollection \ test. php (28): B-> b1 ()
#2 D: \ workspace \ myzCollection \ test. php (37): c-> c1 ()
#3 C: \ Program Files \ Zend \ ZendStudio-5.2.0 \ bin \ php5 \ dummy. php (1): include ('d: \ workspace \ my ...')
#4 {main} end
Second Test:
Remove throw $ e from b1, that is, do not throw it.
The result is:
X-Powered-By: PHP/5.1.1
Content-type: text/html
End
Third Test:
Open throw new Exception ($ e-> getMessage () in b1.
Throw a new exception, so that none of the calls above b1 can get the a1 exception.
The result is:
X-Powered-By: PHP/5.1.1
Content-type: text/html
#0 D: \ workspace \ myzCollection \ test. php (28): B-> b1 ()
#1 D: \ workspace \ myzCollection \ test. php (37): c-> c1 ()
#2 C: \ Program Files \ Zend \ ZendStudio-5.2.0 \ bin \ php5 \ dummy. php (1): include ('d: \ workspace \ my ...')
#3 {main} end
Fourth Test:
Remove all try catch throw in b1.
Result:Everything is normal, that is, the middle step does not need to be thrown, and the top layer can also get the Exception thrown at the bottom layer.
There is only one problem. if an exception occurs in B, it cannot be obtained. if you want to detect B, add try catch in B.
X-Powered-By: PHP/5.1.1
Content-type: text/html
#0 D: \ workspace \ myzCollection \ test. php (16): a-> a1 ()
#1 D: \ workspace \ myzCollection \ test. php (28): B-> b1 ()
#2 D: \ workspace \ myzCollection \ test. php (37): c-> c1 ()
#3 C: \ Program Files \ Zend \ ZendStudio-5.2.0 \ bin \ php5 \ dummy. php (1): include ('d: \ workspace \ my ...')
#4 {main} end
Class {
Public function a1 (){
Try {
Throw new Exception ('20140901 ');
} Catch (Exception $ e ){
Throw $ e;
}
}
}
Class B {
Public function b1 (){
Try {
$ A = new ();
$ A-> a1 ();
} Catch (Exception $ e ){
Throw $ e;
// Throw new Exception ($ e-> getMessage ());
}
}
}
Class c {
Public function c1 (){
Try {
$ A = new B ();
$ A-> b1 ();
} Catch (Exception $ e ){
Throw $ e;
}
}
}
Try {
$ C = new c ();
$ C-> c1 ();
} Catch (Exception $ e ){
Echo $ e-> getTraceAsString ();
}
Echo 789;
?>
Use c1 of c in catch, b1 of B in c1, and a1 of a in b1. The default value is: a1 throws an exception, b1 captures the a1 exception, and then throws the exception, c1 captures ,...