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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T04:13:07+00:00 2026-06-05T04:13:07+00:00

Consider the following situation: I have a library that includes a third party library.

  • 0

Consider the following situation: I have a library that includes a third party library. This third party library throws very nice, useful exceptions derived from std::exception. I’d like to communicate these exceptions to the code that calls my library, but I don’t want to have to include the 3rd party library in the calling code, too. That 3rd party library could potentially change later on.

It seems to make sense to create my own classes in my library that inherit from the third party exceptions, like so:

class myException: public thirdParty {};

Is there an easy way to catch an instance of thirdParty and copy it to myException? Later I may add capability to myException, but for now, I really just want to make thirdParty available to the calling code without including third party’s library there.

I do realize, of course, that the calling code will know about thirdParty because the headers from the third party library get included in my library header, which gets included in the calling code. But I’m trying to establish a contract that says, “Hey, these are the exceptions MY library throws. Later, I may swap out the third party lib, but I’m still going to throw exceptions that do what its exceptions did.”

Is this right? Is there a better way of doing this? Should I just have my calling code be aware of thirdParty exceptions?

  • 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-05T04:13:09+00:00Added an answer on June 5, 2026 at 4:13 am

    If the aim is to reduce coupling with the third party library then you should consider your code as the boundary. As such you wouldn’t leak the implementation to your users.

    The question is why do your users need to care about the exception that that the third party library throws? They should care about your code’s abstractions and interfaces.

    So I would not inherit from the those exceptions, rather I would create a series of exceptions that reflect the exceptions I want my code to throw. You can give them the same names but you should be the owner of those exceptions.

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

Sidebar

Related Questions

Consider the following situation where I have a list of n matrices (this is
Consider the following situation: We have two Localizable.string files, one in en.lproj and one
Consider the following situation: I have two android projects named P1 and P2 which
Consider following scenario: I have RESTful URL /articles that returns list of articles user
Consider the following common situation: You have some MainView in your Cocoa application, loaded
Consider a situation: I have a buffer of known length that presumably stores a
Consider the following situation. I have 3 tables in a resource planning project(created using
Consider the following situation: There is an xml that contains data @XmlData The @XmlData
So, please consider the following situation I have a super class of type Shapes
Consider I have the following situation: I have a branch br_foo from revision 4.

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.