Jump to content

Need advice on a clean way to handle custom errors.


atrum

Recommended Posts

So it has recently occurred to me that my method of error handling is sloppy and cumbersome. What I want to do is record all of the errors that occur and allow the page to finish loading. Then display them in a designated error panel on my page.

 

Granted that if I come across a major error I do want to stop the script but for minor errors such as incorrect credentials or some other custom error I may want to display I want to neatly display them all without stopping the script.

 

Can anyone offer any advice?

  • 1 month later...

You can try to use different types of Exception. You use a "User_Exception" if you have invalid input data or something like that, and a "Database_Exception" for great errors, like loose connection.

 

It can be like this:

 

try {
    $newUser = new User();
    $newUser->setCredentials('user', 'pass');
    $newUser->insert();
} catch (Database_Exception $e) {
   // log this error
   // stop the script
} catch (User_Exception $e) {
   // Display the error
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.