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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T06:44:56+00:00 2026-06-12T06:44:56+00:00

I have a problem with a c++ library that I develop: I defined my

  • 0

I have a problem with a c++ library that I develop: I defined my own exception class (that basically only contains a string to return for the what() call) and when an exception is not caught, the goal is that the operating system would print the message from what() and terminate. This works well on Linux but on osX, the exception message is not shown (ie it directly terminates without printing anything).

So, am I correctly assuming that uncaught exceptions would lead to what() followed by a termination? What should I do on osX so the message would be shown? (knowing that I don’t like the idea of setting an exception handler, since this imposes the user of the library to do it)

Thanks!
Mathias

  • 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-12T06:44:57+00:00Added an answer on June 12, 2026 at 6:44 am

    So, am I correctly assuming that uncaught exceptions would lead to what() followed by a termination?

    No. The standards don’t require uncaught exceptions to print out what(). In fact, they make it pretty hard (but not impossible) to write a conforming implementation that always does so.

    There’s really no good way to do exactly what you want to do (print out the what(), only if the implementation isn’t going to do so in this case, then carry on to terminate() as if the exception had never been caught). But that probably isn’t what you really want.

    This is probably what you want:

    #import <exception>
    #import <iostream>
    
    int real_main(int argc, char *argv[]);
    
    int main(int argc, char *argv[]) {
      try {
        return real_main(argc, argv);
      } catch (std::exception &e) {
        std::cerr << "exception: e.what()" << "\n";
        exit(1);
      } catch (...) {
        std::cerr << "exception not derived from std::exception\n";
        exit(1);
      }
    }
    
    int real_main(int argc, char *argv[])
    {
        // real main code goes here
    }
    

    If you really want to, say, _exit or abort (or even terminate) instead of exiting, you can do that of course. But if you don’t know, you probably want exit.

    Meanwhile:

    … knowing that I don’t like the idea of setting an exception handler, since this imposes the user of the library to do it

    You’re writing a library? And you want your library to be able to terminate the process behind the application’s back?

    That’s probably a very bad idea.

    But if you really do want to do it, the same code above will work, you just have to wrap it around the entry points to your library instead of around main.

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

Sidebar

Related Questions

I have the following problem that the standard library doesn't solve well, and I'm
I have a problem with a socket library that uses WSAASyncSelect to put the
This is a problem i have with data that i receive from a library
I have a main task (to develop a library) that I split up to
I have a problem that can basically be summirized as: Byte[] barr = new
I have an interesting problem. I currently have a basic template library that renders
So I have a strange problem with the raphael.js library that makes no sense
I have a library A, that I develop. When I deploy it on a
I have a little problem with the library 'Telerik'. Indeed I want to implement
I have a problem with a specific java client library. Here is the situation:

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.