Exception Handling in Pure C

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 by the OS, so is there any function for C that causes the same behavior from the OS as try catch and throw? Thanks.

+7
c exception-handling
source share
4 answers

C itself does not support exception handling. However, an exception handling tool for C exists on the basis of the platform + compiler.

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

I have seen arguments in the past that a pair of C functions setjmp and longjmp are exception handling in C. I find it closer to the throw pattern, but worth exploring

+7
source share

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

+2
source share

Not platform independent. And this will only be for hardware / OS level exceptions, not for SW exceptions.

+1
source share

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

+1
source share

All Articles