Copyright statement: original works can be reproduced. During reprinting, you must mark the original publication, author information, and this statement in hyperlink form. Otherwise, legal liability will be held. Http://blog.csdn.net/mayongzhan-ma yongzhan, myz, mayongzhan
Thank you, Mr. Cao...
It mainly tests multi-level usage exceptions.
Note the bold words in blue.
Use C1 of C in try catch on the page, 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
<? PHP
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;
?>