|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2009-12-11 02:44 UTC] randallgirard at hotmail dot com
Description:
------------
The documentation does not state for the function set_exception_handler(...) that it will terminate processing. I do not see much of a reason for such a handler if you do not have this option. Unless I am missing something, please include such documentation or fix this in the next release. Take for example set_error_handler() which forces you to handle termination of the script (when necessary) from code.
NOTE: I am using v5.3.0 on my local machine for testing, and havent tested on my server which runs 5.3.1 but I doubt this is the case.
Reproduce code:
---------------
function exception_handler($exception) {
echo "Uncaught exception: " , $exception->getMessage(), "\n";
}
set_exception_handler('exception_handler');
function errorone() {
throw new Exception("Test 1");
}
function errortwo() {
throw new Exception("Test 2");
}
function test() {
errorone();
errortwo();
}
test();
test();
# I also did further tests involving class scopes that I thought might affect this, but I'm almost positive processing of the script is terminated without a way to restore it.
Expected result:
----------------
Uncaught exception: Test 1\nUncaught exception: Test 2\nUncaught exception: Test 1\nUncaught exception: Test 2\n
Actual result:
--------------
Uncaught exception: Test 1\n
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Nov 30 18:00:01 2025 UTC |
HERE is my current error handler code that I wrote yesterday? <?php namespace frm { # ------------- ERROR HANDLING abstract class error { public static $LIST = array(); public static function initiate( $log = false ) { # setup error handling # NOTE: If namespaces are used, they must be specified in the below calls: # ex: '\\my_namespace\\error::handler' set_error_handler( '\\frm\\error::err_handler' ); set_exception_handler( '\\frm\\error::exc_handler' ); # If $log is set (should be a file) then enable logging and set ERROR_LOG if ( $log !== false ) { if ( ! ini_get('log_errors') ) ini_set('log_errors', true); if ( ! ini_get('error_log') ) ini_set('error_log', $log); } } # Error handler (catch unhandled errors) public static function err_handler($errno, $errstr, $errfile, $errline, $errcontext) { $l = error_reporting(); if ( $l & $errno ) { # determine error type and if we exit or not $exit = false; # The following error types are not supported because they get thrown BEFORE RUNTIME: # E_ERROR, E_PARSE, E_CORE_ERROR, E_CORE_WARNING, E_COMPILE_ERROR, E_COMPILE_WARNING switch ( $errno ) { case E_USER_ERROR: $type = 'Fatal Error'; $exit = true; break; case E_USER_WARNING: case E_WARNING: $type = 'Warning'; break; case E_USER_NOTICE: case E_NOTICE: # error handling is for PHP versions < 5.2 case @E_STRICT: $type = 'Notice'; break; case @E_RECOVERABLE_ERROR: $type = 'Catchable'; break; # unknown error type: # ...just in case a new error type is added default: $type = 'Unknown Error'; $exit = true; break; } $exception = new \ErrorException($type.': '.$errstr, 0, $errno, $errfile, $errline); if ( $exit ) { # MAKE SURE we exit termination exc_handler($exception); exit(); } else # NOTE: Uncaught exceptions cause the script to terminate processing and does NOT continue throw $exception; } return false; } # Exception handler - catch unhandled exceptions, perform logs, etc function exc_handler($exception) { $log = $exception->getMessage() . "\n" . $exception->getTraceAsString() . LINEBREAK; # log error if enabled if ( ini_get('log_errors') ) error_log($log, 0); print("Unhandled Exception" . (DEBUG ? " - $log" : '')); } } } ?> Now, if an (for example) E_USER_WARNING or E_USER_NOTICE error is triggered without a TRY block in the parent scope then script execution terminates and doesn't allow me to control whether or not processing is terminated.