SignalMapping Struct Reference

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

Data Fields

int signalNumber
 The signal to be converted.
const Exceptionexception
 The exception representing the signal.

Detailed Description

Represents a map between a signal and an exception.

exceptions4c can make your life easier by converting each signals to a Exception. Most of these signals would crash your program as soon as they were raised. Now you can catch signals and avoid core dumps.

For example, you could wrap a suspicious or dangerous part of the code with try blocks and catch segmentation faults or divisions by zero. Then you can clean up and keep working:

 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 simpler way to get this working is by calling function:

 extern void beginExceptionContext(bool handleSignals);

beginExceptionContext will set up for you the default handlers for the available signals in the platform if you pass handleSignals=true.

If you need to be more specific about which signals get converted to exceptions, you can define an array of SignalMapping this way:

 SignalMapping mapping[] = {
     SIGNAL_MAPPING(SIGABRT, YourVeryOwnException),
     /* ... */
 }
 

...and then pass it to the function:

 extern void setSignalHandlers(const SignalMapping * mapping, int 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:


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 1.3
Copyright 2010 Guillermo Calvo.

Generated on 24 Jan 2010 by doxygen 1.6.2