Re: fexception handling in C





siliconwafer wrote:
> Hi All,
> I am using C on linux and performed a 1/0 operation i.e a divide by
> zero using integer variables/constants.it gives me a floating point
> exceptionand the program terminates.
> I want to access the routine that causes this message to occour and
> want to modify it so that my program continues to run.How is exception
> handling done in C?Is there a try-catch equivalent?

Interesting that you got a floating-point exception
from an integer calculation ... As far as C is concerned,
attempting to divide by zero produces "undefined behavior,"
meaning that anything at all can happen -- you can get a
floating-point exception, or a bogus answer without any kind
of error indication, or your CPU may overheat and melt into
a puddle of impure glass.

The C language itself makes no promises about what might
happen, but the particular system on which you're running C
might. If so, you'll need to check with people who know the
details of how your system operates; they may be able to tell
you some tricks that go beyond what C itself can deliver.

And no, C has no built-in exception handling, nor any
way to "repair and resume" a failed program. Again, your
system might provide some such capabilities as extensions
to C -- but again, you'll need to ask the system experts,
not the C experts.

--
Eric.Sosman@xxxxxxx

.



Relevant Pages

  • Re: TRAP 0000 in OS2KRNL
    ... That was a 'divide by zero' error where it wasn't dividing by zero. ... The meaning of the exception is actually 'divide overflow' - it's just that ... Further proof that you are a troll, ...
    (comp.os.os2.bugs)
  • Re: Exceptions are not raised
    ... you're expecting a "divide by zero" exception, but it will not occur, ... dividing by zero is not an illegal operation. ... Dim num1, num2 As Short ...
    (microsoft.public.dotnet.general)
  • Re: TRAP 0000 in OS2KRNL
    ... That was a 'divide by zero' error where it wasn't dividing by zero. ... The meaning of the exception is actually 'divide overflow' - it's just that ... But shouldn't the system protect itself from such a crash by ...
    (comp.os.os2.bugs)
  • Re: C to Delphi set problems
    ... In other words, it's undefined, and should throw an exception. ... to divide by zero. ... could be said for trying to find the lowest element in a set that is empty. ...
    (comp.lang.pascal.delphi.misc)
  • Re: INVALID_HANDLE_VALUE vs. NULL
    ... 0 (zero) can never be a valid handle value. ... Of course, ReadFilewill fail with this handle, ... > CloseHandle() does indeed fail when given a bad handle. ... > case it raises an exception. ...
    (microsoft.public.win32.programmer.kernel)