Is there a way to trap errors and do certain things based on what error is received?
Say, if I get a "Function not defined error" can I, instead of it displaying the error message, have it go to a main function?
Printable View
Is there a way to trap errors and do certain things based on what error is received?
Say, if I get a "Function not defined error" can I, instead of it displaying the error message, have it go to a main function?
I did this on one of my recent projects (this works well with sql statements, and I think you can use it for other functions too:
PHP Code:function ErrorHandling($type,$message) {
echo "Type: $type<br />Message: $message";
}
$query = mysql_query("select * from table") or die(ErrorHandling("MySQL Query",mysql_error());
Great idea! But why doesn't this work?:
It prints the normal thing and prints the eval_error() function. :confused:PHP Code:eval($_REQUEST["action"] . "();") or die(eval_error());
That is why.Quote:
From php.net
A return statement will terminate the evaluation of the string immediately. In PHP 4, eval() returns FALSE unless return() is called in the evaluated code, in which case the value passed to return() is returned. In PHP 3, eval() does not return a value.
I think what I'm doing is bad anyways, so I ditched the idea.