Jump to content

Custom Exceptions - when to use?


phant0m

Recommended Posts

Hi

 

I was wondering how you use custom exceptions.

I find it difficult to balance between just using different error messages and using new Exception Classes, because I want to be able to react to different kinds of Exceptions and I am not too fond of using error codes.

 

I tend to create new Exception classes so I can just have multiple catch blocks.

How do you use Exceptions?

Link to comment
https://forums.phpfreaks.com/topic/202372-custom-exceptions-when-to-use/
Share on other sites

Whats wrong with multiple catch blocks?

 

try {
   //call classes/autoload or whatever you wish to do
   //program runs here

} catch (UserErrorException $e) {
   //Display error
} catch (FormHandlerException $e) {
   //Display error with form data
} catch (Exception $e) {
   //Redirect to error page...
}

 

I can't see a problem with that?

  • 4 weeks later...
  • 3 weeks later...

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.