Not sure if this answers your question, but the code within the catch { ... }
only ever gets executed if something in the preceding try { ... }
block throws an exception for any reason. Therefore, any code in the try { ... }
will execute normally and completely unless you either explicitly throw
an exception or some function/class you are calling throws an exception. At that moment, the code being processed stops at that point and "throws" control to the applicable catch
block (if there is one -- if not, your code basically just dies). Maybe this will help:
<?php
try {
echo "In the try{} block...<br />\n";
throw new Exception("This was thrown from the try block.");
echo "This will not be output.<br />\n";
} catch(Exception $e) {
echo "We're in the catch{} block now.<br />\n";
echo $e->getMessage()."<br />\n";
}
echo "This is after the try/catch.<br />\n";
throw new Exception("This is an uncaught exception<br />\n");
echo "This will never get displayed since the preceding line will kill the script.<br />\n";
Test run output:
14:27 $ php catch.php
In the try{} block...<br />
We're in the catch{} block now.<br />
This was thrown from the try block.<br />
This is after the try/catch.<br />
PHP Fatal error: Uncaught Exception: This is an uncaught exception<br />
in /Users/********/projects/catch.php:13
Stack trace:
#0 {main}
thrown in /Users/********/projects/catch.php on line 13