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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T14:04:17+00:00 2026-05-30T14:04:17+00:00

In my app Im using different open source libraries , that throws different exceptions

  • 0

In my app Im using different open source libraries , that throws different exceptions .
I don’t have experience in dealing in way with exception handling ,I always just did the try/catch thing , when I know
there is problem .
Now I like to build some kind of object that handles all exceptions inside it . and I don’t have idea how to start and even if it possible
For example I have my class A and B

Class A 
{
 void method1() 
{
  Foo foo = new foo // external lib throws throw std::bad_alloc();
}
};

Class B 
{
 Void method1() 
{
  Int d = m_foo[0] // external lib  throw std::runtime_error( message );
}
};

I want somehow to handle those kinds and others in central place in my application
What strategy should I use ?

UPDATE :
after trying the suggestion offered and implemented the try/catch in the main of my application , the problem it never gets there when the exception throws all im getting is this but its never gets to the try/catch:
visual studio run time error

  • 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-30T14:04:18+00:00Added an answer on May 30, 2026 at 2:04 pm

    You can use a try... catch structure in your main() function. All exceptions of the C++ standard library derive from std::exception, so that’s a good back up. However, you should discriminate all different kinds of exceptions, or at least, those more common. You can also create your own exceptions, as classes deriving from std::runtime_error. You can have multiple catch sections, but ordered from the one more specific to the more general one.

    try {
    
    // more things...
    
    }
    catch(const std::bad_alloc &ba)
    {
        // memory error
        std::cerr << "Memory error" << std::endl;
        exit( EXIT_FAILURE );
    }
    catch(const std::runtime_error &re)
    {
        // customized error, probably
        std::cerr << "ERROR: " << re.what() << std::endl;
        exit( EXIT_FAILURE );
    }
    catch(const std::exception &e)
    {
        // general (unexpected) error
        std::cerr << "Unexpected ERROR: " << e.what() << std::endl;
        exit( EXIT_FAILURE );
    }
    

    Remember you need to #include stdexcept and exception.
    Hope this helps.

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

Sidebar

Related Questions

I have an app using PHP and the PayPal API. The basic way it
I know that I can load an app.config file from a different location using
I have an iPhone app that is using sqlite 3.6 (not with FMDB) to
I have an app using a ListView as a main screen. Each row displays
I have an iPhone app using a UINavigationController. On the fourth controller of the
I have an app using SQLite3. It's running pretty well, but I would like
I have an app using the ADO.NET entity framework (the VS2008 version, not the
I have a web app using forms authentication and I have restricted a folder
I've been going through some open-source code for a Twitter app, and came across
I am building an app that needs to dynamically/programatically know of and use different

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.