Jump to content

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...
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.