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 ' End ';? >
The page in the try Catch uses C in the C1,C1 using B's b1,b1 to use a's A1.
The default is: A1 throws an exception, B1 captures the A1 exception, then throws the exception just now, C1 captures, then throws, the last page captures and outputs.
The result is:
x-powered-by:php/5.1.1
Content-type:text/html
#0 D:\workspace\myzCollection\test.php (+): A->A1 ()
#1 D:\workspace\myzCollection\test.php (): B->b1 ()
#2 D:\workspace\myzCollection\test.php (PNS): C->c1 ()
#3 C:\Program files\zend\zendstudio-5.2.0\bin\php5\dummy.php (1): Include (' D:\workspace\my ... ')
#4 {Main}end
A second Test:
The B1 inside the throw $e removed, is not thrown.
The result is:
x-powered-by:php/5.1.1
Content-type:text/html
End
A third Test:
throw new Exception ($e->getmessage ()) inside the B1; open.
Throws a new exception so that B1 calls above do not get A1 exceptions.
The result is:
x-powered-by:php/5.1.1
Content-type:text/html
#0 D:\workspace\myzCollection\test.php (): B->b1 ()
#1 D:\workspace\myzCollection\test.php (PNS): 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 the try catch throw from the B1.
Results:
still output The original exception, that is, the intermediate steps do not need to be thrown, the topmost can also get the lowest thrown exception.
There is only one problem, b if the first exception, there is no way to take, if you need to also detect B, then also in B to add a try catch
x-powered-by:php/5.1.1
Content-type:text/html
#0 D:\workspace\myzCollection\test.php (+): A->A1 ()
#1 D:\workspace\myzCollection\test.php (): B->b1 ()
#2 D:\workspace\myzCollection\test.php (PNS): C->c1 ()
#3 C:\Program files\zend\zendstudio-5.2.0\bin\php5\dummy.php (1): Include (' D:\workspace\my ... ')
#4 {Main}end