OODuck
0.5
C Oriented Object framework with duck-typing support
|
Public Attributes | |
int | signal_number |
const e4c_exception_type *const | exception_type |
Represents a map between a signal and an exception
A signal is an asynchronous notification sent by the operating system to a process in order to notify it of an event that occurred. Most of the signals will, by default, crash the program as soon as they are raised. exceptions4c can convert signals to exceptions, so they can be easily handled.
For example, a suspicious or dangerous part of the program could be wrapped up with try
blocks and then catch
segmentation faults or divisions by zero. Then the program would clean up and continue normally:
In order to perform the conversion, exceptions4c maps signals to exceptions.
The simplest way to get this working is by calling the function e4c_context_begin
. This function will set up the default mappings for the available signals in the platform, when passed handle_signals=true
.
If you need to be more specific about which signals get converted to exceptions, you can define an array of signal mappings and then pass it to the function e4c_context_set_signal_mappings
.
An array of signal mappings is defined through three macros:
While E4C_SIGNAL_MAPPING
tells the system to convert a specific signal to a given exception, E4C_IGNORE_SIGNAL
allows you to disregard the signal and continue (even if unmeaningful).
Every array of signal mappings needs to be terminated with the E4C_NULL_SIGNAL_MAPPING
element, so the system finds out how many mappings are there in a given array.
Once the array is properly defined, it can be passed to the function e4c_context_set_signal_mappings
. This way, only the specified signals will be handled as exceptions, and they will be converted to the specified exceptions.
These are some of the signals you can handle:
SIGFPE
when dividing by zero.SIGSEGV
when dereferencing an invalid pointer.SIGINT
when a user interrupts the process.SIGTERM
when a process is requested to be terminated.const e4c_exception_type* const e4c_signal_mapping::exception_type |
The exception representing the signal
int e4c_signal_mapping::signal_number |
The signal to be converted