Hi
I am in the process of building a new framework and I want to get the core functionality sorted as best as possible can before I go too far. I’ve now got to my errors and exceptions module; I want all default errors and uncaught exceptions be handled in one place. Getting this far isn’t too tricky, however displaying useful error information is!
Here’s what I’ve got so far:
<?
// Custom error handler
function errorHandler($errno, $errstr, $errfile, $errline) {
throw new Exception($errstr, $errno);
}
set_error_handler('errorHandler');
// Custom exception handler
function exception_handler($exception) {
ob_end_clean();// Clean the buffer
print "<br />";
print "Uncaught exception: " . $exception->getMessage();
print "<br />";
print "Line: " . $exception->getLine();
}
set_exception_handler('exception_handler');
// Start ob
ob_start();
// Create an error
file_put_contents('cosmos:\\1.txt', 'asdf');
?>
This will output the following:
Uncaught exception: file_put_contents(cosmos:\1.txt) [function.file-put-contents]: failed to open stream: Invalid argument
Line: 4
The problem with this code is when I the error is returned it is pointing back to line 4. Line 4 is where the exception is thrown and not where the error occurred (line 24). Does anyone know how this could be extended to display the correct error information?
Jon