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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T12:31:56+00:00 2026-06-13T12:31:56+00:00

If I have a method marked throw(), e.g. void method() throw() { // do

  • 0

If I have a method marked throw(), e.g.

 void method() throw()
 {
      // do some stuff, call other functions
 }

and yet exception does happen inside, gcc will terminate the application (with message “terminate called after throwing an instance of ‘xyz'”).

Is there a way to avoid this behaviour?

For example, a command-line switch to ignore throw() stuff or force eh_frame generation. Etc.

  • 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-13T12:31:56+00:00Added an answer on June 13, 2026 at 12:31 pm

    Did you try the GCC manual?

    -fno-enforce-eh-specs

    Don’t generate code to check for violation of exception specifications at run time. This option violates the C++ standard, but may be useful for reducing code size in production builds, much like defining `NDEBUG‘. This does not give user code permission to throw exceptions in violation of the exception specifications; the compiler still optimizes based on the specifications, so throwing an unexpected exception results in undefined behavior at run time.

    It doesn’t force generate of EH frames, but it should stop the call to std::unexpected() and so might be useful for your case.

    As the docs say, “the compiler still optimizes based on the specifications” so e.g. it doesn’t help when the call to method() can be inlined into the catch site, because the compiler assumes the catch is not needed, because the empty exception spec says no exception will be throw, and so if an exception is thrown it doesn’t get caught. If the call to method() is not inlinable into the catch site it seems to work, the exception leaves method() without calling std::unexpected() and can be caught higher up the stack.

    Edit: This will still call std::terminate() even with -fno-enforce-eh-specs:

    void func() throw() { throw ""; }
    void func2() { func(); }
    int main() { try { func2(); } catch (...) { } }
    

    The compiler can see that the call to func2 only calls a no-throw function, so the catch will never be needed and so is optimised away. When the exception is thrown, it isn’t caught.

    This does work with -fno-enforce-eh-specs and doesn’t terminate:

    /* func2.cc */
    void func() throw();
    void func2() { func(); }
    
    /* main.cc */
    void func2();
    int main() { try { func2(); } catch (...) { } }
    

    Here, when compiling main.cc, the compiler can’t tell whether func2 is going to throw or not because it has no exception specification and its definition is not visible in main.cc, so the catch cannot be omitted. When the exception is thrown it will be caught.

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

Sidebar

Related Questions

I've got some 3rd party beans that have method signatures that fit quite well
I've a problem with the annotation @Transactional . I've a method doing some stuff,
For some reason i have a hard time calling a delegate method from within
I have an interface with an annotated method. The annotation is marked with @Inherited
I have a method that looks like this: try { doStuff(); } catch (Exception
I have a ListView with some focusable components inside (mostly EditText s). Yeah, I
I have method that returns Drawable , and if its Bitmap object is recycled
I have method that returned NSManagedObject and I don't know what kind of NSManagedObject
I have method with two parameters: bool1 and bool2. Both are boolean of course.
I have method that returns module path of given class name def findModulePath(path, className):

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.