Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exception libraries for C (not C++)

I am rolling my own exception library for C and would like good examples to examine.

So far, I have been looking at David Hanson's: http://drhanson.net/work/

But I know I've seen other ones available in the past. Can you send me some additional pointers?

Thanks,

SetJmp

like image 783
Setjmp Avatar asked Sep 11 '09 11:09

Setjmp


People also ask

What are exceptions in C?

Master C and Embedded C Programming- Learn as you go A C++ exception is a response to an exceptional circumstance that arises while a program is running, such as an attempt to divide by zero. Exceptions provide a way to transfer control from one part of a program to another.

Does C language have exceptions?

C does not have exception handling facilities. Errors are handled by examining the value returned by each function and signals (conditions reported to the program) are handled by using library functions.

Can we handle exceptions in C?

The C programming language does not support exception handling nor error handling.

How do you handle exception in C?

As such, C programming does not provide direct support for error handling but being a system programming language, it provides you access at lower level in the form of return values. Most of the C or even Unix function calls return -1 or NULL in case of any error and set an error code errno.


2 Answers

Here is one, compatible with C89 and implementing the try/catch/finally schema as can be found in other OO languages.

like image 112
philant Avatar answered Sep 21 '22 23:09

philant


Symbian implemented exceptions (called 'leaves') in terms of longjmp. This was C++ code, but translatable to C. There's a previous post about this.

like image 22
Will Avatar answered Sep 18 '22 23:09

Will