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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T22:53:17+00:00 2026-06-05T22:53:17+00:00

I have made my own exception class which derives from runtime_error and is getting

  • 0

I have made my own exception class which derives from runtime_error and is getting an int in the c’tor.

I would like to make a base class for this exception, in order to use polymorphism, so I could catch only the base class and basically I would be catching the derived class.

So, this is the base class: (and in another cpp file I got baseException::~baseException(){})

class baseException
{
    virtual ~baseException()=0 {}
};

And this is the derived class:

class myException: public runtime_error, public baseException
{
public:
    myException(int): runtime_error("Error occured") {}
};

Note that I do not have any actual error in the base class, it’s only role is to enable me polymorphism on my future custom exception classes I will make.
That is why it only has a pure virtual d’tor. I do not need any “actual” object of this BaseException class.

Though, when I try to catch baseException in the main and call what(), I can not.
How do I make it work?

  • 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-05T22:53:17+00:00Added an answer on June 5, 2026 at 10:53 pm

    The first problem is that you’re missing the () from the destructor’s declaration, and there’s a rogue : after the class name.

    Once you’ve fixed that, you’ll probably get an error like:

    error: pure-specifier on function-definition
    

    For some reason known only to the C++ standards committee, pure virtual functions cannot be implemented within the class definition like that. If you want it to be pure virtual, then you’ll need to move the definition outside the class:

    class baseException
    {
        virtual ~baseException()=0;
    };
    
    inline baseException::~baseException() {}
    

    You’ll also need to decide whether myException derives from runtime_exception or runtime_error: you use one in the class header, and the other in the constructor’s initialiser list. Assuming you’re using the standard exception types, it should probably by std::runtime_error (and, if there’s a using namespace std; in your header file, then you should remove it to avoid breaking code that doesn’t expect the global namespace to be polluted like that).

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

Sidebar

Related Questions

So i have made my own dict-based named-tuple class: class t(dict): def __getattr__(self, v):
I have made a YUI module a little like the code shown below, which
I have made my own file type (.ddd) and I made a simple program
I have made my own sms app with a reciver. Now the emulator doesn'T
I have made Catifier.com recently, and once the user sets their own background image,
I have made a game which is nearly identical to Popcap's Atomica. ( http://www.popcap.com/gamepopup.php?theGame=atomica
I have made a generic Observer interface and an Observable class, but can't compile
I have made a basic ascx control which is just a panel with a
I have a website made in Asp.net MVC which is installed in the root
Question: I want to implement a sessionAccess class, which throws a SessionExpired-Exception when an

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.