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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T21:49:39+00:00 2026-05-11T21:49:39+00:00

I have 2 APIs from 2 different companies that allow me to communicate with

  • 0

I have 2 APIs from 2 different companies that allow me to communicate with their servers in order to process transactions. I am tasked with creating a generic interface to these APIs. I came up with something like this:

IServiceProvider <- ServiceProvider <- CompanyAServiceProvider
IServiceProvider <- ServiceProvider <- CompanyBServiceProvider

In CompanyAServiceProvider I am using the API that they offer to interface with their remote servers. This API from company A throws exceptions that are completely different from Company B’s.

I can handle the exception locally but I don’t really think that suites the situation.

public String purchase(String amount) {
  try {
    request = new Request( RequestIF.NEW_ORDER_TRANSACTION );
  } catch ( InitializationException e ) {
    //do something.
  }
}

Or I can throw this exception to the caller:

public String purchase(String amount) throws Exception {
  request = new Request( RequestIF.NEW_ORDER_TRANSACTION );
}

And let the caller handle just the Exception no matter what that exception is and no matter what API throws it.

How can I write an interface to 2 different APIs and keep it generic when I am dealing with 2 different sets of thrown exceptions. Am I dealing with this correctly? What would be the best choice?

  • 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-11T21:49:39+00:00Added an answer on May 11, 2026 at 9:49 pm

    In this case I create my own Exception sublcass and just wrap the actual exception. My API then exposes only my exception.

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

Sidebar

Related Questions

Are there any PayPal APIs to process multiple transactions at once? I'm creating a
I have a page which requests information from several apis, some of them with
Does Kdiff3 have APIs available? Or is there any comparison tool's API available that
So I have a web application that integrates with several other APIs and services
Folks, We have been using OpenXml APIs found in System.IO.Packaging for creating a package
I have a PHP application that calls web services APIs to get some objects
I am in the process of writing a web-app that uses multiple web APIs.
I have a thread that calls various APIs of a COM interface. Now I
I have always liked the documentation on Java APIs, generally speaking, but I know
DirectDraw 7 is very old APIs but we have a lot legacy code written

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.