Page 1 of 1

Dynamic Errors

Posted: Sun Aug 07, 2005 3:20 am
by Ree
I'm trying to find a way to comfortably handle and pass errors through my scripts. I have a few classes that do stuff, and they return error messages to the script where i use them. Some of those errors are dynamic (such as mysql_error()). I often have this kind of setup: a user enters info in a form, then the data is sent to some script where it is processed (by using the classes which may return errors), after that the user is redirected to some page, on which I want to display any error that may have occured. How can I pass dynamic error messages from my script to that page? I can't simply use //page.php?error=[int] and then use conditionals to check which error message to display, because in the case of mysql_error(), there are more than 2K of them. I hope you understand what I mean. How should I do it? Any ideas/suggestions are very welcome.

Posted: Sun Aug 07, 2005 4:19 am
by Sander
I'm not entirely sure if this is what you want, but you can use the set_error_handler() function to display the errors however you want. You can simply use a switch() to see what the error type is, and display a message based on that.

Posted: Sun Aug 07, 2005 5:40 am
by Ree
I don't know if this is what I need... Say, one of the objects used in the script sends an error message

Code: Select all

'MySQL Error: ' . mysql_error()
So I recieve the error string in the script and now I have the error. As I said there are ~2K of mysql_error() messages, so I can't pass the error like this: //page.php?error=[int] and use a simple switch() on page.php to display the error message...

To make it as simple as possible, the basic idea is this: in my script I may recieve some error string (which could be any string, that is, I don't know the possible values of the string) and I want to pass it to some other page to be displayed there. So switch() won't help here because I don't know what the string could be. How can I achieve this?

And overall I'm interested how you guys handle your errors.

Posted: Sun Aug 07, 2005 7:29 am
by feyd
My errors are pooled, classified, sometimes destroyed (handled away), if and only if a fatal error occurs do I halt processing.. (sometimes because php will halt it for me :?)

Posted: Sun Aug 07, 2005 1:15 pm
by Ree
Are you sure you guys can't help me here? I may seem a bit impatient, but I really can't find a solution... :?

Posted: Sun Aug 07, 2005 2:02 pm
by josh
Store the error message in the database along with a unique ID, pass that unique ID in the query string, or if you want just use sessions.