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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T14:00:29+00:00 2026-05-19T14:00:29+00:00

What kind of exception is thrown when there’s a divide by zero error? I

  • 0

What kind of exception is thrown when there’s a divide by zero error? I tried using the “catch-all” catch(...), but Visual Studio still complains that there’s an unhandled exception.

int a = 0;
try
{
    a /= a;
}
catch (/* what should I catch?*/)
{
    cout << "divide by zero error" << endl;
}

Note: I’m not asking how to prevent this type of problem before-hand (e.g. checking if a is zero before trying to divide by zero).

  • 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-19T14:00:29+00:00Added an answer on May 19, 2026 at 2:00 pm

    This is not a C++ question, because there is no way to do so in standard C++.

    In Windows, this generates a Structured Exception Handling exception.

    See this example from MSDN:

    __try 
    { 
        *pResult = dividend / divisor; 
    } 
    __except(GetExceptionCode() == EXCEPTION_INT_DIVIDE_BY_ZERO ? 
             EXCEPTION_EXECUTE_HANDLER : EXCEPTION_CONTINUE_SEARCH)
    { 
        return FALSE;
    }
    

    This is non-portable and specific to Windows, though. Last I knew GCC doesn’t support it either, even on Windows.

    In case you are asking a broader question, the way it works is your CPU will generate an interrupt when you do a divide by zero. The Windows kernel handles this and delivers it to your process, giving you an opportunity to handle it. If you don’t handle it your process dies. On Unix type OSs the same will hold, but it will probably result in a signal. I am not sure which one.

    I would say if you want to write portable C++ code it’s probably better to check for divide by zero in software rather than rely on hardware to generate a fault and for the OS kernel to deliver it to you via some non-portable mechanism.

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

Sidebar

Related Questions

Hi all patient developers using spring data graph. Since there is so less documentation
Most program languages have some kind of exception handling; some languages have return codes,
Kind of a basic question but I'm having troubles thinking of a solution so
Kind of a weird question, but. I need to have a list of strings
Kind of the opposite of this question . Is there a way to tell
Kind sirs, I'm using Codeigniter to build a blog. I might need a way
I'm using VS2010 in C# there is a place in my code where an
I just started using Eclipse so go easy on me ;). But when trying
(I know there's some close duplicates out there, but none of them were able
While developing using ASP.net 2.0 (C#) and NHibernate 2.1.0 I am getting the error:

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.