7

Possible Duplicate:
C : How do you simulate an 'exception' ?

Hi, I know that exception handling is available in C++ but not in C. But I also read that exception handling is provided from OS side, so isnt there any function for C invoking the same behavior from OS as try catch and throw? Thanks.

Community
  • 1
  • 1
B.Gen.Jack.O.Neill
  • 8,169
  • 12
  • 51
  • 79
  • 6
    Duplicate: [C : How do you simulate an 'exception'?](http://stackoverflow.com/questions/1219438/), [How do I implement exceptions with nestable try-catch-finally statement with messages in C](http://stackoverflow.com/questions/1779189/), [Exception libraries for C (not C++)](http://stackoverflow.com/questions/3581818/), [Exception libraries for C (not C++)](http://stackoverflow.com/questions/1410329/) and related: [How are exceptions implemented under the hood?](http://stackoverflow.com/questions/1995734/), [How to throw an exception in C?](http://stackoverflow.com/questions/2891766/) etc. – dmckee --- ex-moderator kitten Oct 19 '10 at 15:09
  • Come on, B.Gen, you're not new here. You know how things work. – dmckee --- ex-moderator kitten Oct 19 '10 at 15:12

4 Answers4

7

The C language itself has no support for exception handling. However a means of exception handling for C does exist on a platform + compiler specific basis.

In windows for example C programs can use SEH exception handling.

I've seen arguments in the past that the C function pair setjmp and longjmp is exception handling in C. I consider it closer to the ejection pattern but it's worth investigating

JaredPar
  • 733,204
  • 149
  • 1,241
  • 1,454
2

Not in a platform-independent way. And this would only be for hardware/OS-level exceptions, not SW exceptions.

Oliver Charlesworth
  • 267,707
  • 33
  • 569
  • 680
2

C provides exceptions in a standard library: setjmp()/longjmp().

Joshua
  • 40,822
  • 8
  • 72
  • 132
1

I don't think there is a true, pure, portable C solution. For Microsoft compilers, you can use __try __except, see http://msdn.microsoft.com/en-us/library/zazxh1a9(VS.80).aspx

Emile
  • 2,200
  • 27
  • 36