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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T17:47:49+00:00 2026-06-16T17:47:49+00:00

This is probably a broad question, not quite SO style, but I’d still like

  • 0

This is probably a broad question, not quite SO style, but I’d still like to get some hints or guidelines if possible.

I’ve been looking through some legacy code and found a part of it that has methods with exceptions nested 3 or 4 levels down.
Is this considered to be a normal practice or should one avoid such codestyle where possible? If it should be avoided, what are the negative effects besides the increasing costs of exception handling and decreasing readability? Are there common ways of refactoring the code to avoid this?

  • 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-16T17:47:49+00:00Added an answer on June 16, 2026 at 5:47 pm

    I personally prefer the following ideology

    Wrap Alien Exceptions

    An “alien” exception is an exception thrown by a Java API or a third party library. In other words, an exception you do not control.

    Its better to catch all alien exceptions and wrap them in an appropriate application specific exception. Once the alien exception is converted to your own exception, you can propagate that exception any way you like.

    Rethrowing Checked Exceptions can get Messy

    If your application uses checked exceptions, rethrowing the original exception means that the method rethrowing it must also declare it.

    The closer you get to the top of the call hierarchy, the more exceptions will be declared thrown. Unless you just declare all your methods to throw Exception. However, if you do so you might as well use unchecked exceptions, since you are not really getting any benefit from the compiler exception checking anyways.

    This is why I prefer to catch non-application specific exceptions and wrap them in an application specific exception, before propagating them up the call stack.

    Guidelines For Wrapping : The context in which an exception occurs may be just as important as the location of the exception itself. A given location in the application may be reachable via different execution paths, and the execution path may influence the severity and cause of the error, if it occurs.

    If you need to add context information to an exception as you propagate it up the call stack, you need to use active propagation. In other words, you need to catch the exception in various relevant locations on the way up the call stack, and add the relevant context information to it, before rethrowing or wrapping it.

    public void doSomething() throws SomeException{
    
        try{
    
            doSomethingThatCanThrowException();
    
        } catch (SomeException e){
    
           e.addContextInformation(“more info”);
           throw e;  //throw e, or wrap it – see next line.
    
           //throw new WrappingException(e, “more information”);
    
        } finally {
           //clean up – close open resources etc.
        }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

this probably is a basic question, but can I do something like this: Class
This probably sounds like a nightmare, but I'd really like to get this working.
This probably sounds like a terrible idea at first glance, but here is my
This probably is a dummy question but I cannot find a clear indication. I
I know this probably really simple but Im not sure what im doing wrong...
Im sorry for this probably dumm question, but I want to simply open modals
This probably isn't something you should try at home, but for some reason or
This probably has to do with asynchronous code, but I'm not sure what. The
This probably is a very very basic question but i can't seem to find
I know this probably is a fairly complicated question but... heres my case: I

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.