PHP: Exception not caught by try ... catch

Posted by Christian Brenner on Stack Overflow See other posts from Stack Overflow or by Christian Brenner
Published on 2012-12-17T22:40:06Z Indexed on 2012/12/17 23:03 UTC
Read the original article Hit count: 267

Filed under:
|
|

I currently am working on an autoloader class for one of my projects. Below is the code for the controller library:

     public static function includeFileContainingClass($classname) {

        $classname_rectified = str_replace(__NAMESPACE__.'\\', '', $classname);
        $controller_path     = ENVIRONMENT_DIRECTROY_CONTROLLERS.strtolower($classname_rectified).'.controller.php';

        if (file_exists($controller_path)) {

           include $controller_path;
           return true;

        } else {

           // TODO: Implement gettext('MSG_FILE_CONTROLLER_NOTFOUND')
           throw new Exception('File '.strtolower($classname_rectified).'.controller.php not found.');
           return false;

        }

     }

And here's the code of the file I try to invoke the autoloader on:

  try {

     spl_autoload_register(__NAMESPACE__.'\\Controller::includeFileContainingClass');

  } catch (Exception $malfunction) {

     die($malfunction->getMessage());

  }

  // TESTING ONLY
  $test = new Testing();

When I try to force a malfunction, I get the following message:

Fatal error: Uncaught exception 'Exception' with message 'File testing.controller.php not found.' in D:\cerophine-0.0.1-alpha1\application\libraries\controller.library.php:51 Stack trace: #0 [internal function]: application\Controller::includeFileContainingClass('application\Tes...') #1 D:\cerophine-0.0.1-alpha1\index.php(58): spl_autoload_call('application\Tes...') #2 {main} thrown in D:\cerophine-0.0.1-alpha1\application\libraries\controller.library.php on line 51

What seems to be wrong?

© Stack Overflow or respective owner

Related posts about php

Related posts about exception