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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T11:45:16+00:00 2026-05-24T11:45:16+00:00

At the moment i working with library which can throw hell alot of different

  • 0

At the moment i working with library which can throw hell alot of different exceptions(8-10 per method call) and most of them must be handled, worse of all every method (at any time) can throw AuthenticationExpiredException, and i must re-attempt to authenticate. For example:

try {
        xStream = xSet.createXStream(id, binding, mimeType); //Method call
    } catch (AuthenticationExpiredException authenticationExpiredException) {
        try {
        this.authenticate(); // re-authenticate
        xStream = xSet.createXStream(id, binding, mimeType); //Method call again
        } catch (XAMException xamException) {
        throw new ConnectorException(
            "Error occurred during creating new Blob after attempting to re-authenticate",
            xamException);
        }
    } catch (XSystemCorruptException xSystemCorruptException) {
        this.entities.clear();
        this.closeConnection();     

        throw new ConnectorException("XSystem was corrupt and connection was closed",
            xSystemCorruptException);
    } catch (XSetCorruptException xSetCorruptException) {
        this.closeEntity(entity);

        throw new ConnectorException("XSet for entity: " + entity.getXuid()
            + " was currupt and removed", xSetCorruptException);
    } catch (XAMException xamException) {
        throw new ConnectorException(
            "Error occurred during creating new Blob.", xamException);
    }

And this is one of the smallest examples of exception handling. The main question here, is there any way to reduce amount of code which handle exceptions, and make logic cleaner?

UPDATE

Thanks for your feedback. I decided to create separate wrapper for this library by wrapping every method and handling them respectively. To support different handling methods i created interface for wrapper and then implemented it with my custom wrapper like this:

public interface XAMLibraryWrapper{
    // Methods
}

/**
 * Will attempt to recover before throwing RuntimeException
 */
public class RecoveringXAMLibraryWrapper implements XAMLibraryWrapper{
    // Implementation
}
  • 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-24T11:45:17+00:00Added an answer on May 24, 2026 at 11:45 am

    If there is a consistent way to handle those method (i.e. you always wrap them in the same way and re-throw a RuntimeException, then a custom wrapper library might be the appropriate approach. This can still work when there are 2-3 different ways to handle them (by providing 2-3 wrapper methods (or even classes) for a single wrapped method/class).

    Alternatively, if two or more exception types have the exact same handling code, then you can try to look for Java 7 to get multi-catch.

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

Sidebar

Related Questions

I am working through the 20 Intermediate Haskell Exercises at the moment, which is
My problem is this: I am trying to implement a C++ library which can
At the moment I am working on creating a small library for common data
I am working on a method in a library. The method is passed a
Whoopee, not working on that socket library for the moment. I'm trying to educate
At the moment I'm working on an iPad explore game which has a hexagon
I'm exploring envers at the moment and working through the documentation. There is one
At the moment I am working on a project admin application in C# 3.5
Working on a project at the moment and we have to implement soft deletion
I'm working on a project at the moment, migrating an existing site to a

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.