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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T11:17:28+00:00 2026-05-15T11:17:28+00:00

It is known how to catch the float division-by-zero exception with the usage of

  • 0

It is known how to catch the float division-by-zero exception with the usage of

signal(SIGFPE, handler)

but it doesn’t catch integer division-by-zero problem even if I setup control word with

_control87(0, _MCW_EM ); (MS VC 2010)

SubQuestion_1: How to catch integer division-by-zero in C program in Windows without usage of SEH EXCEPTION_INT_DIVIDE_BY_ZERO? (In Unix/Linux this can be done with usage of the standard signal/SIGFPE techinque)

EDIT:
signal is ANSI C signal handling approach.
_control87 is the standard Windows function to set float control word.

Similar question: How to handle all errors, including internal C library errors, uniformly

NOTE (from ISO/IEC 9899:TC2 Annex H.2.2):

“The signed C integer types int, long int, long long int, and the corresponding
unsigned types are compatible with LIA−1. … C’s unsigned integer types are ‘‘modulo’’ in the LIA−1 sense in that overflows or out-of-bounds results silently wrap. An implementation that defines signed integer types as also being modulo need not detect integer overflow, in which case, only integer divide-by-zero need be detected.“

?FINAL SOLUTION:

For Windows: it throws SEH exception. So it can be caught by usage of __try __except.
As possible solution SEH translation could be used to handle SEH exception and translate them to call of needed function. It is not a “natural” way, but it seems that it’s the only way.

For Unix: it could be caught with signal/SIGFPE solution. Or check wiki for FPE_INTDIV solution ( http://rosettacode.org/wiki/Detect_division_by_zero#C ).

As GMan was right about “undefined behaviour” I’m choosing his answer as correct.

Note: It is interesting to check VC\crt\src\winxfltr.c: _XcptActTab array : )

  • 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-15T11:17:29+00:00Added an answer on May 15, 2026 at 11:17 am

    Division by zero leads to undefined behavior, there is no C language construct that can do anything about it. Your best bet is to not divide by zero in the first place, by checking the denominator.

    If you want to “catch” (note, C has no exceptions) this error, it will be dependent on your compiler and OS, which you haven’t listed. By the way, _control87 has only to do with floating-point operations, and nothing to do with integer operations.

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

Sidebar

Related Questions

It is discouraged to simply catch System.Exception . Instead, only the "known" exceptions should
I know try catch have been discussed a lot but I haven’t found a
We know that we can catch any unexpected exception at application level by using
Anyone knows why my sql query doesn't work after using a try catch function?
Sometimes, I'll end up having to catch an exception that I know can never
given a traceback error log, i don't always know how to catch a particular
Does anyone know how can I catch a mail error (error is displayed while
I'd like to know the Haskell way to catch and handle exceptions. As shown
Anyone know a good external link tracking script ? IE. to catch links and
As far as I know, I put in the correct try catch statements to

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.