Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8330569
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T02:09:44+00:00 2026-06-09T02:09:44+00:00

As a rule I try to avoid throwing instances of Exception, because this doesn’t

  • 0

As a rule I try to avoid throwing instances of Exception, because this doesn’t convey much information about what went wrong.

But I’m finding that I’m getting a fair number of empty Exception classes, which look like this…

class DataNotFoundException extends Exception {
   // just a tagging class
}

So functionally the class is identical to Exception. The only functional significance is I can now do this…

try {
    ... some code which throws exceptions ...
} catch (DataNotFoundException $dnfe) {
    ... do stuff ...
} catch (OtherException $oe) {
    ... do other stuff ...
}

My question is, where is the balance between having a huge number of tiny Exception classes and just throwing instances of Exception. Does anyone have any guidelines for when to introduce a new Exception class?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T02:09:46+00:00Added an answer on June 9, 2026 at 2:09 am

    It’s not a bad practice to include lots of specific exceptions, but only ones relevant and reproduce able. If you choose to be very specific with them, it should go in a specific order, as well; going from very specific, to general.

    try {}    catch (CryptographicException e)
    { ...doSomething }
    
    catch (ArgumentOutOfBoundsException e)
    { ...doSomething }
    
    catch (Exception e)
    { ...doSomething }
    

    This being attributed to the processing of events, and if a general Exception is first, all others will be skipped. Having specific exceptions before general ones will help in the idea that you acquire more information from them, as well.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The following htaccess rule doesn't work because of the umlauts. Redirect 301 /xyz/händedruck.html /new/händedruck.html
I try to write some simple rules and I get this ambiguity rule: field1
When I try to execute this DQL query: SELECT r, s FROM Rule r
I'm unhappy with the rule about variable scope in a try block not being
I try to call a function which checks a rule and if the rule
I notice that sometimes when I try to override a CSS rule, browser does
This rule works fine for http://foo.com/page/contact RewriteRule ^page/([^/\.]+)/?$ index.php?page=$1 [L] But what I want
I have this rule in my .htaccess RewriteRule ^([^/\.]+)/?$ ?page=user&id=$1 [L] It rewrite a
Ok saddle up cowboys, because this is going to be a long one. I
I want to make some custom htaccess rule for some page in magento.for this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.