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 8497493
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T00:08:28+00:00 2026-06-11T00:08:28+00:00

Are there reasons why you would want to do this: void foo() throws Exception

  • 0

Are there reasons why you would want to do this:

void foo() throws Exception
{
    // Do something potentially exceptional
}

Rather than throwing an existing or custom exception?

  • 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-11T00:08:30+00:00Added an answer on June 11, 2026 at 12:08 am

    There’s two cases I can potentially think of – the first similar case I can think of is when implementing finalize(), you have to throw Throwable:

    @Override
    protected void finalize() throws Throwable {
        super.finalize();
    }
    

    …though bear in mind some argue that using finalize should be discouraged in itself.

    The potential second case is when using a (badly written) library whose method(s) may throw an Exception, in which case if you don’t want to deal with it in that particular method your only option is to throw it up the stack.

    Personally though, if that were me I’d most likely wrap it up in a RuntimeException then and there:

    public void doSomething() {
        try {
            int x = libraryThing.badMethod(); //Library method that throws "Exception"
        }
        catch(Exception ex) {
            throw new RuntimeException("Couldn't do something", ex);
        }
    }
    

    The second argument to RuntimeException‘s constructor is important in this case though, since if it is thrown that will preserve the original exception on the stack trace as (“Caused by: x”). Of course, if you can find a more specific subclass of RuntimeException that you can guarantee is relevant in that context (IllegalArgumentException for instance) then using that would be better.

    In terms of normal code however, nope – I’d argue it’s nearly always an anti-pattern (and usually one just caused through laziness!)

    As a side point, throwing a RuntimeException isn’t so bad – it’s still very unspecific but at least doesn’t force the caller to catch everything explicitly.

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

Sidebar

Related Questions

There are many security reasons why one would want to drop an HTTP connection
Are there any good reasons for why you would include JavaScript like this: <script
I know there are LOTS of reasons why you would compose a certain object
I want to store short arrays in a field. (I realize there are reasons
Is there a reason you would not set -static-link-runtime-shared-libraries to true when compiling an
If I'm running a suite of tests, is there a reason I would NOT
Is there any reason why printw() would cause a segmentation fault? Code is fine
Is there any conceivable reason why I would see different results using unicode string
Is there any reasons why PHP's json_encode function does not escape all JSON control
Are there any good reasons to modify your project's build output path from its

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.