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

  • SEARCH
  • Home
  • 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 7515097
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T00:41:41+00:00 2026-05-30T00:41:41+00:00

Besides the obvious case of treating different exceptions differently, is there any benefit in

  • 0

Besides the obvious case of treating different exceptions differently, is there any benefit in treating exceptions separately? I see a lot of code that looks something among the lines of:

try {
    doSomethingThatMayThrowExceptions();
} catch (SomeException e) {
} catch (OtherException e) {
}

I always tend to just catch the generic Exception when I only have one exception-handling process.

A derived question would be: is it better in any way to state the exact type of exception you are catching, if it’s just one? For example:

try {
    number = Integer.parseInt(numberString);
} catch (Exception e) {
    // ...
}

In the above example, the try block can only throw a NumberFormatException. Is there any downside to catching the generic Exception here?

  • 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-05-30T00:41:42+00:00Added an answer on May 30, 2026 at 12:41 am

    In the above example, the try block can only throw a NumberFormatException. Is there any downside to catching the generic Exception here?

    Not really. But it can be asked, what do you achieve by “hiding” the exact exception?

    If you catch NumberFormatException, you can instantly see which exceptions are expected to be thrown.

    EDIT: Pardon me. The above example can also throw unchecked exceptions ie. NPEs, so you’re actually catching more exceptions and treating them all the same way. You might actually want to implement different exception handling for those exceptions (if you even want to catch and handle unchecked exceptions).

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

Sidebar

Related Questions

Besides the obvious fact that there's no sidebar in Windows 7, are there any
Besides readability is there any significant benifit to using a CASE WHEN statement vs
Quick question here: is there any obvious benefit to use asynchronous communication with the
Besides the DateTime ctor (new DateTime(year, month, day)) , is there any other way
Besides using script or an iframe, is there any way to get independently operating
Besides the obvious answer of buy an iphone 4 (I'm in Australia so that's
Besides the obvious reason of storing any type as an object and storing it
Maybe this is a silly question but is there a difference,besides the obvious,between android:text=@string/....
Besides ASP.NET MVC's obvious conventions, what libraries do you take advantage of that minimize
Besides the difference in how characters are stored, are there any special characters in

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.