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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T10:57:43+00:00 2026-05-15T10:57:43+00:00

In the course of asking about catching ‘divide by 0’ exception, I found that

  • 0

In the course of asking about catching ‘divide by 0’ exception, I found that with C++, we can’t do that. I mean, divide by 0 doesn’t throw an std::exception.

Some of the hints that I found were I have to check the value, and throw the exception by self.

I say it’s confusing, as I’ve thought that C++ adopted the exception idea in order to replace the ‘good old C/UNIX report error by returning value method’.

Here are my questions

  • Q1 : Why C++ doesn’t throw std::exception error for divide by 0? Is there any reason behind that?
  • Q2 : Normally, what error processing scheme the C++ users use? Always throw an error, and the exception is the divide by 0 error?
  • Q3 : In general, OOP languages prefer (or even enforce) using exception. Is this correct?
  • 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-15T10:57:44+00:00Added an answer on May 15, 2026 at 10:57 am

    C++ assumes you know what you’re doing, doesn’t pay for things you don’t ask for, and makes no assumptions about the platforms it’s intended for.

    If you want to divide numbers, it would be quite inefficient to mandate the compiler check the denominator and throw before dividing. (We didn’t ask it to do that.) So that option is out; we can’t have this check on every division, and it’s especially wasteful since most divisions are not by zero.

    So, how can we just divide by zero and find out if it worked? Because C++ cannot assume anything about it’s platform, it cannot assume there is a way to check the result, hardware-wise. That is to say, while many CPU’s will jump to an interrupt of some sort when division by zero occurs, the C++ language cannot guarantee such a thing.

    The only option then is to let the behavior be undefined. And that’s exactly what you get: undefined behavior.


    OOP languages might do something or another, it doesn’t matter since OOP isn’t well-defined and C++ isn’t an OOP language anyway. In general, use the tool that’s most appropriate. (Exceptions are for exceptional situations.)

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

Sidebar

Related Questions

I'm wondering about the feasability of this below. Of course, I'm not asking for
Hello yeah I'm asking this question a second time, sorry about that but I
Of course, I can explain it in whole books. But I read a few
Of course we can do this, but is it alright to do so? Are
Hey, first, let me say, I'm not asking about things like md5(md5(..., there are
I'm working on a 32-bit windows application that can occasionally run out of memory
after asking question about Instruments and finding problems with my code there are two
I'm asking this mainly about Java, but I guess it applies to a whole
I'm talking about a library that would allow me to log events from different
I'm taking a cloud computing course and have a few problems that I am

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.