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.
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.
- http://www.microsoft.com/msj/0197/Exception/Exception.aspx
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
- http://msdn.microsoft.com/en-us/library/aa272905(VS.60).aspx
Not in a platform-independent way. And this would only be for hardware/OS-level exceptions, not SW exceptions.
C provides exceptions in a standard library: setjmp()/longjmp().
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
精彩评论