View Full Version : Proces PHP erromessage to custom message

04-27-2004, 09:40 PM
On one specific point in one of my scripts, I want to trap a possible error. The possible error will be something like

Warning: Division by zero in
c:\phpdev\fp_dataproces.php(761) : eval()'d code on line 13

I want to strip of the "Warning: " and the "in c:\phpdev\fp_dataproces.php(761) : eval()'d code on line 13" so that i only keep the "Division by zero."

Anyone knows an efficient way to do this?

The executed code is dynamically build at runtime so i can't use a regex to trap something like ' / 0 '. I also can't check against the inputvalues (long story).
I've been thinking about using the outputbuffer (starting it before the computations and then checking if it's empty after the computation and if so proces it but thats a bit overkill. (The code to do this then also needs to be build at runtime so this means i'd need to build and eval() it maybe 999 times without needing it, for each 1000 requests.
I've now stopped errorreporting right before the computation and print a more general errormessage ("Invalid inputvalue used") and then reset errorreporting right after that, but i would like to get the real PHP-errormessage.

04-27-2004, 10:04 PM
I don't know if this will help, but I came across this tutorial to help deal with error-handling:

There's a method called set_error_handler() that might point you in the right direction. I've never done anything like this myself, so I don't know if it will actually help.

Good luck,

04-27-2004, 10:24 PM
Thanks for the reply.

But they all just more a less just buffer theoutputmessage and then either run their own checks with defined errormessages, or write theerror to a file.

I was hoping there was an easy and efficient way to just somehow specify which parts of the errormessage need to be returned (like only the type, or the actual errortext, or the line it's on etc), so that i can store it in a variables :(

04-28-2004, 03:16 AM
the custom error logging functions dont require that you use buffering , they can work at runtime , check out the first example @ http://www.php.net/errorfunc its OTT but gives a good example usage

04-28-2004, 05:47 AM
I knew it should have been something simple like that, but i couldn't find it.

thanks firepages :thumbsup: