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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T04:46:21+00:00 2026-05-29T04:46:21+00:00

I have made a class to try exceptions: class precExcp:exception { public: virtual const

  • 0

I have made a class to try exceptions:

class precExcp:exception
{
    public:
    virtual const char* what()
    {
        return "Precision must be positive";
    }
};

The problem is that when an exception is launched, the instructions flow doesn’t stop.
I don’t know is this is c++ default behaviour.
If yes, what to do if I want to interrupt instructions flow when an exception is caugth?
This is an example of what I do in main:

int main(int argc, char **argv)
{
    try
    {
        if(1)
            throw precExcp();
    }
    catch(precExcp& e)
    {
        cerr << e.what() <<endl;
    }
    cout << "hello" <<endl;
}

On the screen the “hello” string is printed, is that normal? How to avoid this?

  • 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-29T04:46:22+00:00Added an answer on May 29, 2026 at 4:46 am

    Based on what I can understand from your question, if you want the “hello” output to be skipped, put it in the try block.

    try
    {
       if(1)
           throw precExcp(); // throwing here will skip all remaining 
                             // instructions in the try block
        cout << "hello" <<endl;
    }
    catch(precExcp& e)
    {
        cerr << e.what() <<endl;
    }
    

    Also note that this isn’t Java or Python. C++ exception-handling generally doesn’t require you to define or catch too many different exception-types, as your main source of recovery is going to be the destructor (@see RAII) which often eliminates the need to have multiple catch branches (as well as a finally block). Often you can just catch const std::exception& (make precExcp a subclass of it) and only in some rare cases do you need more granular checking than that.

    You can also rethrow:

    try
    {
       if(1)
           throw precExcp(); // throwing here will skip all remaining 
                             // instructions in the try block
    }
    catch(precExcp& e)
    {
        cerr << e.what() <<endl;
        throw; // throw the original exception
    }
    

    However, if you do this in main and have no catch block to catch that second throw, it’s going to crash with an unhandled exception which may or may not be what you are seeking.

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

Sidebar

Related Questions

I have made a class which a form can inherit from and it handles
I have made an class which conforms to the NSCoding protocol and does all
I have a class made up of several fields, and I have several constructors.
I have a JavaScript class that I have made and put it into its
I have made a generic Observer interface and an Observable class, but can't compile
This is a C++ class that I have made with n number of pointers.
I have to use a class/assembly made in C# .NET from native C++ application.
I have a custom-made view that extends the View class. I would like 2
I have made some user-defined exceptions and I would like to add an error
I have made a class with name of Movie with folowing fields: @Id @GeneratedValue

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.