Dynamic Errors
Moderator: General Moderators
Dynamic Errors
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.
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.
I don't know if this is what I need... Say, one of the objects used in the script sends an error message
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.
Code: Select all
'MySQL Error: ' . mysql_error()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.