Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exception Handling in C without C++ in Linux

Does Linux provide an exception handling in C without resorting to C++? Or, what might be the best way to implement such an exception handling? The goal is to avoid to check return codes for every function called, but do something like in C++ that is thread safe and easily portable.

like image 208
stefangachter Avatar asked Aug 27 '10 06:08

stefangachter


2 Answers

You can handle the signals by writing your signal handlers for it. Some of these signals documented at GNU are:

  • Program Error Signals: Used to report serious program errors.
  • Termination Signals: Used to interrupt and/or terminate the program.
  • Alarm Signals: Used to indicate expiration of timers.
  • Asynchronous I/O Signals: Used to indicate input is available.
  • Job Control Signals: Signals used to support job control.
  • Operation Error Signals: Used to report operational system errors.
  • Miscellaneous Signals: Miscellaneous Signals.
  • Signal Messages: Printing a message describing a signal

You can get more info in depth about this here. It states the following which I suppose is what you are looking for:

If you anticipate an event that causes signals, you can define a handler function and tell the operating system to run it when that particular type of signal arrives.

like image 110
Praveen S Avatar answered Oct 02 '22 15:10

Praveen S


I've never heard of Linux providing anything like that, but this page describes a third-party exception handling library for C: http://www.on-time.com/ddj0011.htm I haven't been able to find the download link, though.

like image 26
EMP Avatar answered Oct 02 '22 15:10

EMP