PHP Exception not being caught
<p>Im working on a class to make SVN changes through a PHP application. I'm calling svn commands through exec() and trying to throw an exception on error to revert any changes.</p>

<p>Here is the relevant part of the SVN class:</p>

<pre><code>private function svn_exec($cmd) {
        $out = array();
        $err = 0;
        exec($cmd, $out, $err);

        if ($err) {
            throw new SVNException("$cmd exited with a status of $err");
        }
    }
</code></pre>

<p>And the custom Exception, contained in the same file as the SVN class:</p>

<pre><code>    class SVNException extends \Exception {
    public function __construct($message = null, $code = 0, \Exception $previous = null) {

        error_log("SVN Error: " . $message);

        parent::__construct("A Subversion error has occurred.", $code, $previous);
    }
}
</code></pre>

<p>And the calling code in another class:</p>

<pre><code>public function ApplySVNChanges() {
    try {
                $svn-&gt;update();

                // Do a bunch more stuff...

                $svn-&gt;commit();
            } catch (\utils\SVNException $se) { 
                error_log("Exception caught in SVN class."); // &lt;-- Being logged
                $svn-&gt;revert();
                throw $se; // Throw to caller so db changes are rolled back
            }
}
</code></pre>

<p>SVN Update is throwing an SVNException, before I can move on to why I need to figure out my the application is crashing and not handling the SVNException like it should. According to the error logs the SVNException is being unhandled. The call to $svn->update() is in a try/catch block that should catch SVNExceptions however, so I'm confused as to why it isn't being handled.</p>

<blockquote>
  <p>PHP Fatal error:  Uncaught exception 'utils\SVNException' with message 'A Subversion error has occurred.' in /path/SVNFunctions.php:114\nStack trace:\n#0 /path/SVNFunctions.php(73): utils\SVNFunctions->svn_exec('svn update --us...')\n#1 /path/CallingClass.php(120)</p>
</blockquote>

<p>Update: After adding messages to the catch blocks to log when exceptions are being caught, I found that the SVN exception is being caught, but when rethrown the method above it that calls it isn't catching it. The original <code>try catch</code> block is part of a method that gets called by another method with its own block to revert SVN and db changes to keep them synced.</p>

<pre><code>try {
        ApplySVNChanges(); // Throws SVNException

        // Database related changes...          

        $db-commit();
    } catch (Exception $e) {
        error_log('Caught Exception in main caller.'); // &lt;-- NOT being logged

        if($e instanceof \core\DatabaseException OR $e instanceof \utils\SVNException) {           
            $db-&gt;rollback();
        } else {
            throw $e;
        }
    }
</code></pre>

<p>According to the error logs the update command is throwing the exception. It is being caught by the first catch, revert is called, and the <code>catch</code> in the calling method for Database and SVN Exceptions isn't catching it.</p>