CoreException

Filepath: phork/php/ext/core/CoreException.class.php

The CoreException class is used to handle any application errors that occur, whereas user generated errors use trigger_error() and CoreError. The PHP manual has more information on exceptions and how they work.

The CoreException constructor sets up itself as the exception handler as well. When an uncaught exception is encountered it prints a backtrace of what happened.

Generally you'll want to catch exceptions and display a user friendly error of some sort, however if verbose errors are turned on in the global configuration then you can display a backtrace of the problem.


Example Exception

throw new CoreException('This is an exception');

Example Handling (from index.php)

//register and run the bootstrap to build the page
try { 
    $objBootstrap = new SiteBootstrap(array(
        'strInstallDir'       => $strInstallDir,
        'strSiteDir'          => $strSiteDir,
        'strConfigDir'        => $strConfigDir
    ));
    AppRegistry::register('Bootstrap', $objBootstrap);
    $objBootstrap->run();    
}
    
//handle core exceptions by showing details or a generic error
catch (CoreException $objException) {
    if (AppConfig::get('ErrorVerbose')) {
        $objException->handleException();
    } else {
        $objException->flushBuffer();
        if ($objError = AppRegistry::get('Error', false)) {
            $arrErrors = $objError->flushErrors();
        }
        require(AppConfig::get('TemplateDir') . 'system/error.phtml');
    }
}

//handle any other exceptions with a generic message
catch (Exception $objException) {
    print 'There was a fatal error';
}