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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T15:39:46+00:00 2026-05-15T15:39:46+00:00

I’ve read a few other posts like this one about avoiding repetition in Java

  • 0

I’ve read a few other posts like this one about avoiding repetition in Java catch blocks. Apparently, what I really want is “multi-catch”, but seeing as Java 7 isn’t here yet, is there a good pattern to let me add state to my exceptions, then re-throw them, without catching the kitchen sink?

Specifically, I have some code that makes library calls, which can throw exceptions, but don’t provide nearly enough context for successful debuging. I find myself having a problem, then going in, wrapping the library call in a try/catch, catching the specific exception, then adding extra state information in the catch block and re-throwing the caught exception. I then re-iterate through that loop over and over, each time finding a new error condition to log. I wind up with

try {
  make_library_call();
}
catch (SomeException e){
  throw new SomeException ("Needed local state information is " + importantInfo, e);
}
catch (SomeOtherException e){
  throw new SomeOtherException ("Needed local state information is " + importantInfo, e);
}
catch (YetAnotherException e){
  throw new YetAnotherException ("Needed local state information is " + importantInfo, e);
}

etc etc. I think what I’d really like to see is more along the lines of

try {
  make_lib_call();
}
catch(Exception e){
  e.AddSomeInformationSomehow("Needed Info" + importantInfo);
  throw e;
}

assuming that in that case e would keep its actual runtime type when re-thrown — in this case, even catching unchecked would probably be OK since I’d be re-throwing them, and they’d benefit from carrying the extra state info as well. I guess an alternate might be something like

try{
  make_lib_call();
}
finally {
  if (/*an exception happened*/)
    logger.debug("Some state info: " + importantInfo);
}

but I don’t know how to write the conditional. Is that crazy / wrong?

  • 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-15T15:39:46+00:00Added an answer on May 15, 2026 at 3:39 pm

    You’re probably expecting this, but no, there isn’t a good (and by good I mean clean) way to do this. You’re probably expecting it because you subconsciously knew that if there was a good pattern for doing this, it probably wouldn’t have been worth adding to Java 7.

    It’s actually the final rethrow feature that you’d find really handy in this case.

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

Sidebar

Ask A Question

Stats

  • Questions 487k
  • Answers 487k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You can do something like that in MS Access, but… May 16, 2026 at 8:28 am
  • Editorial Team
    Editorial Team added an answer To my knowledge, there's no means for combining the .bak… May 16, 2026 at 8:28 am
  • Editorial Team
    Editorial Team added an answer Solution 1: Object registration system The two snippets presented essentially… May 16, 2026 at 8:28 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

No related questions found

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.