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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T06:33:30+00:00 2026-05-18T06:33:30+00:00

I have an exception class as follows: #include <exception> struct InvalidPathException : public std::exception

  • 0

I have an exception class as follows:

#include <exception>

struct InvalidPathException : public std::exception
{
   explicit InvalidPathException() {}
   const char* what() const;
};

const char*
InvalidPathException::what() const {
    return "Path is not valid";
}

When compiling under GCC 4.4 with -Wall -std=c++0x

error: looser throw specifier for
‘virtual const char*
InvalidPathException::what() const’

error: overriding ‘virtual const char*
std::exception::what() const throw ()’

Quite right, too, since I’m overriding std::exception‘s what() method that does indeed have a throw() exception specifier. But as one will often be informed, we shouldn’t use exception specifiers. And as I understand it, they are deprecated in C++11, but evidently not yet in GCC with -std=c++0x.

So I’d be interested in the best approach for now. In the code I’m developing I do care about performance and so worry about the oft-mentioned overhead of throw(), but in reality is this overhead so severe? Am I right in thinking that I’d only suffer it when what() is actually called, which would only be after such an exception is thrown (and likewise for the other methods inherited from std::exception that all have throw() specifiers)?

Alternatively, is there a way to work around this error given by GCC?

  • 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-18T06:33:30+00:00Added an answer on May 18, 2026 at 6:33 am

    Empty throw specifications are useful, as they actually enable compiler optimizations at the caller’s site, as Wikipedia knows (I don’t have a technical quote handy).

    And for reasons of optimization opportunities, nothrow-specifications are not deprecated in the upcoming standard, they just don’t look like throw () any more but are called noexcept. Well, yes, and they work slightly differently.

    Here‘s a discussion of noexcept that also details why traditional nothrow-specifications prohobit optimizations at the callee’s site.

    Generally, you pay for every throw specification you have, at least with a fully compliant compiler, which GCC has, in this respect, appearantly not always been. Those throw specifications have to be checked at run-time, even empty ones. That is because if an exception is raised that does not conform to the throw specification, stack unwinding has to take place within that stack frame (so you need code for that in addition to the conformance check) and then std::unexpected has to be called. On the other hand, you potentially save time/space for every empty throw specification as the compiler may make more assumptions when calling that function. I chicken out by saying only a profiler can give you the definitive answer of whether your particular code suffers from or improves by (empty!) throws specification.

    As a workaround to your actual problem, may the following work?

    • Introduce #define NOTHROW throw () and use it for your exception’s what and other stuff.
    • When GCC implements noexcept, redefine NOTHROW.

    Update

    As @James McNellis notes, throw () will be forward-compatible. In that case, I suggest just using throw () where you have to and, apart from that, if in doubt, profile.

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

Sidebar

Related Questions

For my exception class i have a constructor that has multi arguments (...) which
I have heard that using exception trapping is not a recommended practice for number
Most program languages have some kind of exception handling; some languages have return codes,
I have a function in a native DLL defined as follows: #include <string> void
I have an exception handler . In my asp.net application. It’s written in Global.asax.
I have thread exception handler which saves the exception stack trace and should close
I have a general exception handler, Application_error in my global.asax where I'm trying to
Ok, I have a strange exception thrown from my code that's been bothering me
How have you used the Exception.Data property in C# projects that you've worked on?
I have just discovered the nifty unhandled exception handler for cocoa-touch. Now that I

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.