--- /dev/null
+--TEST--
+user defined error handler + set_error_handling(EH_THROW)
+--SKIPIF--
+<?php if (!extension_loaded("spl") || is_dir('/this/path/does/not/exist')) die("skip"); ?>
+--FILE--
+<?php
+$dir = '/this/path/does/not/exist';
+
+set_error_handler('my_error_handler');
+function my_error_handler() {$a = func_get_args(); print "in error handler\n"; }
+
+try {
+ print "before\n";
+ $iter = new DirectoryIterator($dir);
+ print get_class($iter) . "\n";
+ print "after\n";
+} catch (Exception $e) {
+ print "in catch: ".$e->getMessage()."\n";
+}
+?>
+==DONE==
+<?php exit(0); ?>
+--EXPECT--
+before
+in catch: DirectoryIterator::__construct(/this/path/does/not/exist): failed to open dir: No such file or directory
+==DONE==
/* {{{ php_suppress_errors */
PHPAPI void php_set_error_handling(error_handling_t error_handling, zend_class_entry *exception_class TSRMLS_DC)
{
- PG(error_handling) = error_handling;
- PG(exception_class) = exception_class;
- if (PG(last_error_message)) {
- free(PG(last_error_message));
- PG(last_error_message) = NULL;
- }
- if (PG(last_error_file)) {
- free(PG(last_error_file));
- PG(last_error_file) = NULL;
+ EG(error_handling) = error_handling;
+ EG(exception_class) = exception_class;
+
+ if (error_handling == EH_NORMAL) {
+ EG(user_error_handler) = EG(user_error_handler_old);
+ } else {
+ EG(user_error_handler_old) = EG(user_error_handler);
+ EG(user_error_handler) = NULL;
}
- PG(last_error_lineno) = 0;
}
/* }}} */
}
/* according to error handling mode, suppress error, throw exception or show it */
- if (PG(error_handling) != EH_NORMAL) {
+ if (EG(error_handling) != EH_NORMAL) {
switch (type) {
case E_ERROR:
case E_CORE_ERROR:
/* throw an exception if we are in EH_THROW mode
* but DO NOT overwrite a pending exception
*/
- if (PG(error_handling) == EH_THROW && !EG(exception)) {
- zend_throw_error_exception(PG(exception_class), buffer, 0, type TSRMLS_CC);
+ if (EG(error_handling) == EH_THROW && !EG(exception)) {
+ zend_throw_error_exception(EG(exception_class), buffer, 0, type TSRMLS_CC);
}
efree(buffer);
return;
PG(last_error_message) = NULL;
PG(last_error_file) = NULL;
PG(last_error_lineno) = 0;
- PG(error_handling) = EH_NORMAL;
+ EG(error_handling) = EH_NORMAL;
+ EG(exception_class) = NULL;
PG(disable_functions) = NULL;
PG(disable_classes) = NULL;