Suppose you used custom Exception class extensions to handle custom exceptions, for example, for example:
$testObject = new testClass();
and startup:
function __autoload($class_name) { $file = $class_name.'.php'; if (file_exists($file)) { include $file; }else{ throw new loadException("File $file is missing"); } if(!class_exists($class_name,false)){ throw new loadException("Class $class_name missing in $file"); } return true; } try { $testObject = new testClass(); }catch(loadException $e){ exit('<pre>'.$e.'</pre>'); }
The testClass.php file does not exist, so loadException is thrown with the message: The testClass.php file is missing. (and all other details ... line number, etc.)
everything was fine until I decided to hide all errors and instead displayed a 404 page (or 500 pages ...), so naturally I thought about adding the loadErrorPage function.
class loadException { ... function loadErrorPage($code){ $page = new pageClass(); echo $page->showPage($code); } } ... try { $testObject = new testClass(); }catch(loadException $e){ $e->loadErrorPage(500); }
but this has an obvious problem: if the testClass.php and pageClass.php files are missing, then a fatal error is displayed instead of the preferred 404 page.
I am confused: S How do I elegantly handle this exception in the exception descriptor?
source share