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

  • Home
  • SEARCH
  • 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 6904923
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T08:07:15+00:00 2026-05-27T08:07:15+00:00

I am writing a program using gcc in c++. On dec. 5th I posted

  • 0

I am writing a program using gcc in c++. On dec. 5th I posted a question because of a weird problem ( https://stackoverflow.com/a/8392854/837803 ). When a software exception leaves a function declared with no ‘throw’ specifications like this:

int foo();

or this:

int foo() throw();

gcc-generated code will crash.

I want to tell gcc that any kind of software exception could leave any function I write. I think it is something like:

int foo() throw(...);

BUT: I don’t want to write throw(…) in all function specifications. I realise that my program size will be bigger, but that is not a problem for this case. Also, I have read that the behaviour of gcc that I am suggesting, is an ANSI violation. But that is no problem either.

Among the many, many, many command-line options of gcc, there must be one that I am looking for, but I haven’t found it yet.

What is the option I am looking for?

  • 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-27T08:07:16+00:00Added an answer on May 27, 2026 at 8:07 am

    I take exception to this:

    gcc-generated code will crash.

    This is just plain wrong.

    A function declared like this:

     void func1();
    

    If you throw an exception it will cause the stack to unwind upto an appropriate catch. IF there is no appropriate catch the program exits (weather the stack unwinds in this case is implementation defined (thus put a catch all in main)).

    A function declared like this:

    void func2() throw(); // ie no throw.
    

    If an exception escapes this function then unexpected() is called. The default action of unexpected is to call abort() which causes the program to exit (Note: you can replace unexpected with a user defined function but it has to either exit or throw an alternative exception that can pass the throw specification (in this case that is not possible)).

    The behavior you want is the default behavior (with no throw specification). Throw specifications were an experiment that failed and have thus been deprecated. You should not be using them anyway (apart from no-throw).

    So you can get normal working code with exceptions if you define your functions like this:

    void func3(); // Exceptions work fine.
    

    But it is best to put a catch in main()

    int main()
    {
        try
        {
            // DoWork
        }
        catch(std::exception const& e)  // We can print a good error message with these
        {
            log(e.what()); 
            throw;                     // Not much you can do so re-throw for the OS.
        }
        catch(...)                     // Catch all other exceptions.
        {
            log("Unknown Exception");
            throw;                     // Not much you can do so re-throw for the OS.
        }
        // Catching forces the stack to unwind all the way to main()
        // Otherwise it is implementation defined whether it unwinds.
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing a simple program using SDL, but I'm running into a strange problem.
I am using gcc (Ubuntu 4.4.1-4ubuntu9) to compile a program that I'm writing, but
I'm writing a program using the Winsock API because a friend wanted a simple
I am writing a program using Delphi 2006 and storing data in XML files
I'm writing a program using C++ and the MySQL C API (version 5.1.31 ubuntu2).
I am writing an application program using swing. I need to exit from the
I tried writing a program in Java using regex to match a pattern and
I'm writing a program (for Mac OS X, using Objective-C) and I need to
I am writing a program that generates excel reports, currently using the Microsoft.Interop.Excel reference.
I am newbie at using DataSet. I am writing a program with VB.NET, there

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.