开发者

Exception handling in pure C [duplicate]

开发者 https://www.devze.com 2023-01-20 09:44 出处:网络
This question already has answers here: 开发者_如何学C Closed 12 years ago. Possible Duplicate: C : How do you simulate an 'exception' ?
This question already has answers here: 开发者_如何学C Closed 12 years ago.

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

0

精彩评论

暂无评论...
验证码 换一张
取 消