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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T16:57:18+00:00 2026-06-02T16:57:18+00:00

Does anyone know a opensource c++ application with a well designed/robust exception mechanism so

  • 0

Does anyone know a opensource c++ application with a well designed/robust exception mechanism so I can get some inspiration? Most code/examples I see do questionable things like:

  1. Throw objects with a message string as argument. Seems wrong because it marks the exception as fatal, a error message wich can be displayed to the user higher up leaves little room for client code trying to handle the exception. Even if the exception is fatal, things like diffirent locales (languages) makes formatting a message at the point of throw seem like a bad idea to me.
  2. Use tons of different exception classes derived from a base exception class. Just feels wrong introducing a new class/type for every single thing that can go wrong (open file, read file, write file, create thread, etc…). Catching all unhandled exceptions at the highest level using the base type loses type information required to display meaningfull error messages.
  3. Use one exception class derived from a base exception class for every component/library and give it a error code as argument to indicate the exact error. Catching with base type results in ambiguity. (Whose error code “3” did we catch? )…

Some pointers in the right direction would be welcome.

  • 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-02T16:57:19+00:00Added an answer on June 2, 2026 at 4:57 pm

    To address all three of these, I found that the best for me is to throw my own custom exception that’s derived from std::runtime_error. Like this:

    #include <exception>
    
    class ChrisAException : public std::runtime_error
    {
          /// constructor only which passes message to base class
          ChrisAException(std::string msg)
          : std::runtime_error(msg)
          {
    
          }
    }
    

    It allows accepting a string, which I always put in something like the following format (assuming x negative was not a valid input and meant something calling it was in error):

    #include "ChrisAException.h"
    
    void myfunction(int x)
    {
    
        if(x < 0) 
        {
            throw ChrisAException("myfunction(): input was negative!");
        }
    
        // rest of your function
    } 
    

    For this one, keep in mind that the strings in these exceptions are more for the programmer than the end user. It’s the programmer of the interface’s job to display something meaningful in the locale when there’s a failure. The strings in the exception can either be logged or seen at debug time (preferable!)

    This way you can ultimately catch it with:

    try
    {
          // high level code ultimately calling myfunction
    
    }
    catch(ChrisAException &cae)
    {
           // then log cae.what()
    }
    catch(std::runtime_error &e)
    {
           // this will also catch ChrisAException's if the above block wasn't there
    }
    catch(...)
    {
          // caught something unknown
    }
    

    I personally don’t like deriving too many types of exceptions, or giving an error code. I let the string message do the reporting.

    In general, I use C++ exceptions to mean “something went wrong with the program” and not to handle normal use cases. Thus, for me, a thrown exception during the algorithm execution either means “flag the user that something went wrong” or “don’t tell the user” (depending on how critical that code was to what they were doing) but certainly log it and let the programmers know somehow.

    I don’t use C++ exceptions to handle cases that aren’t essentially programming errors, e.g., some kind of incorrect logic or something being called wrong. For example, I wouldn’t use C++ exceptions to handle normal program situations like an empty DVD not being in the drive for a DVD writing program. For that, I’d have explicit return code that allows the user to know whether an empty DVD was there (maybe with a dialog etc.)

    Keep in mind that part of C++ exception handling is to unwind the stack up to a try-catch block. To me that means, abort what’s going on in the program and clean up the stack. In the case of something like my DVD example, you shouldn’t really want to unwind much of the stack. It wasn’t catastrophic. You should simply let the user know and then let them try again.

    But again, this is my preferred way of using C++ exceptions, based on experience and my reading. I’m open to opinions otherwise.

    edit: Changed std::exception to std::runtime_error based on commenter advice.

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

Sidebar

Related Questions

Does anyone know of an easy 3D modeling application like sketchup but is opensource?
Does anyone know any free (not expensive)/OpenSource eCommerce engines designed to work in UK,
Does anyone know how to change icons in Silverlight outofbrowser application?
Does anyone know the best opensource for .NET controls? With Dev Express, Telerik, they
Does anyone know of a open source 3d engine which can be operated via
Does any one know of an opensource Java VNC server, that can be run
Not that I can find any by googling, but ... does anyone know of
Does anyone know of an application (hosted or otherwise) that I could use to
Does anyone know of a solution (preferably open source, so that i can customize
Does anyone know of an open source database proxy where it can serve as

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.