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

The Archive Base Latest Questions

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

I have a base and a derived exceptions, public inner classes of store: //base

  • 0

I have a base and a derived exceptions, public inner classes of store:

//base class - ProductException
    class ProductException: exception
    {
    protected:
        const int prodNum;
    public:
        //default+input constructor
        ProductException(const int& inputNum=0);
        //destructor
        ~ProductException();
        virtual const char* what() const throw();
    };

    //derived class - AddProdException
    class AddProdException: ProductException
    {
    public:
        //default+input constructor
        AddProdException(const int& inputNum=0);
        //destructor
        ~AddProdException();
        //override base exception's method
        virtual const char* what() const throw();
    };

this function which throws the derived exception:

void addProduct(const int& num,const string& name) throw(AddProdException);
void Store::addProduct( const int& num,const string& name )
{
    //irrelevant code...
    throw(AddProdException(num));
}

and a function which calls the function and tries to catch an exception:

try
{
    switch(op)
    {
        case 1:
        {
            cin>>num>>name;
            st.addProduct(num,name);
            break;
        }
    }
}
...
catch(Store::ProductException& e)
{
    const char* errStr=e.what();
    cout<<errStr;
    delete[] errStr;
}

The derived class should get caught, but I keep getting the error “unhandled exception”. Any ideas why? Thanks!

  • 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-05T19:33:55+00:00Added an answer on June 5, 2026 at 7:33 pm

    The reason is that AddProdException is not a ProductException, because you are using private inheritance:

    class AddProdException: ProductException {};
    

    You need to use public inheritance:

    class AddProdException: public ProductException {};
    

    The same applies to ProductException and exception, assuming the latter is an std::exception.

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

Sidebar

Related Questions

I have these classes: class Base { public: virtual void foo(int x = 0)
I have 2 classes: class Base { public: virtual int Foo(int n); virtual void
I have base class BaseClass and derived classes DerivedA , DerivedB , and DerivedC
I have class Base and classes Derived_1 , Derived_2 ... I need derived classes
I have a base class Media and several derived classes, namely DVD , Book
I have a abstract base class A and a set of 10 derived classes.
I have a base class and a dozen derived classes. All but one derived
i want typecast using with class functions. i have base (TBase),derived (TDer) and typecasting
I have a base and derived class called Node which form elements of a
I have a base and derived class. The base class constructors have some static

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.