Custom error handling + trigger error + multiple classes
| From: | daniel at electroteque dot org | Date: | Tue, 13 May 2003 23:48:36 +0000 |
| Subject: | Custom error handling + trigger error + multiple classes | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-147511@lists.php.net to get a copy of this message | ||
hi i am asking this question again , as i dont know if this is gonna work
for me , i have multiple classes with their own internal error handling ,
my authentication and db classes have both in their constructors
something like this
$GLOBALS['_ERROR_HANDLER_OBJECT_DB'] = &$this;
$GLOBALS['_ERROR_HANDLER_METHOD_DB'] = '_db_catch';
function db_error_handler($type, $message, $file=null,
$line=null, $vars=null) {
//die();
return $GLOBALS['_ERROR_HANDLER_OBJECT_DB']->
$GLOBALS['_ERROR_HANDLER_METHOD_DB']($type,$message, $file, $line, $vars);
}
set_error_handler('db_error_handler');
the issue is when i trigger an error within the class the catch function is
triggered from the last class that is set but they have different ways of
throwing the error
here is my catch function
function _db_catch($type, $code, $file=null, $line=null, $vars=null) {
echo $type;
die();
switch ($type) {
case E_WARNING:
//$_SESSION['php_error'] = $code;
$errstr .= "Php Error: $code<br>\n";
$errstr .= "On Line: $line<br>\n";
$errstr .= "In File: $file<br>\n";
//die($errstr);
break;
case E_USER_WARNING:
$this->_throw($code,$file,$line);
break;
}
}
here is the throw function, the real code is commented out
function _throw($code=null,$file,$line) {
//if ($this->show_errors) {
die($this->print_body($this->print_error($_SESSION
['sql_query'],$custom,$line,$file,$break)));
//} else {
// $_SESSION['mysql_error'] = $this->print_body($this-
>print_error($query,$custom,$line,$file,$break));
// $this->redirect("mysql_error.php");
//}
}
basically the throw function for my db class is either going to die to the
screen with my own custom db error parsing which will show the query and
the mysql error and the line and file or go silently to a friendly error
page and email me the error, and the auth class throw function returns to
the previous page with a custom error code set in a session which outputs
the error message
here is the original trigger error
function _trigger_error($query=null,$custom_code=null) {
//die($custom_code);
unset($_SESSION['sql_query']);
if ($query) $_SESSION['sql_query'] = $query;
$trace = debug_backtrace();
$line = $trace[2][line];
$file = $trace[2][file];
die($this->print_body($this->print_error($_SESSION
['sql_query'],$custom,$line,$file,$break)));
//if ($query) $custom_code = $this->print_body($this-
>print_error($query,$custom,$line,$file,$break));
//return trigger_error($custom_code, E_USER_WARNING);
}
as both error handlers in the classes will be triggered from the
E_USER_WARNING the last class is going to handle it, i was hoping it would
be handled internally , is there anyway to set trigger error up so i can do
something like
return trigger_error($custom_code, DB_USER_WARNING);
and for the auth
return trigger_error($custom_code, AUTH_USER_WARNING);
so then it is seperated and only the DB_USER_WARNING will trigger the db
class and the AUTH_USER_WARNING will trigger the auth class please let me
know i'm stumped :\