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.
The result: Everything is normal, that is, the intermediate steps do not need to be thrown, the top 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
Class A {
Public Function A1 () {
try {
throw new Exception (' 123 ');
} catch (Exception $e) {
Throw $e;
}
}
}
Class B {
Public Function B1 () {
try {
$a = new A ();
$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;
?>
http://www.bkjia.com/PHPjc/319773.html www.bkjia.com true http://www.bkjia.com/PHPjc/319773.html techarticle 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 catch A1 exception, and then throw the exception just now, C1 capture, ...