Data Fields

e4c_signal_mapping Struct Reference

Represents a map between a signal and an exception. More...

Data Fields

int signal_number
 The signal to be converted.
const e4c_exception *const exception
 The exception representing the signal.

Detailed Description

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 e4c_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 catch segmentation faults or divisions by zero. Then the program would clean up and continue normally:

 e4c_using_context(true, e4c_print_exception){
     int * pointer = NULL;
     try{
         int oops = *pointer;
     }catch(BadPointerException){
         printf("No problem ;-)");
     }finally{
         /* clean up... */
     }
 }
 

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 e4c_signal_mapping:

 const e4c_signal_mapping my_signal_mappings[] = {
     E4C_SIGNAL_MAPPING(SIGABRT, Exception1),
     E4C_SIGNAL_MAPPING(SIGINT, Exception2),
     ...
     E4C_NULL_SIGNAL_MAPPING
 }
 

An array of e4c_signal_mappings is defined through the macros E4C_SIGNAL_MAPPING and E4C_NULL_SIGNAL_MAPPING. Every e4c_signal_mapping array needs to be terminated by the null signal mapping element, so the system finds out how many mappings there are 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:

See also:
e4c_context_begin
e4c_context_set_signal_mappings
e4c_context_get_signal_mappings
e4c_default_signal_mappings

Field Documentation

The exception representing the signal.

The signal to be converted.


The documentation for this struct was generated from the following file:

exceptions4c version 2.3
Copyright 2010 Guillermo Calvo.

Generated on Wed Nov 24 2010 by doxygen 1.7.2