Error handling

<assert.h>
void assert(expression)
If the expression is false, it raises an Assertion failed during execution
Otherwise, it executes the following instructions
<signal.h>
Provides the means for handling exceptional conditions (signals). A signal is generated when an error or an external event occurs.
Types of signal
MACROs in <signal.h>
:
SIGABRT
Abnormal termination (possibly caused by a call to the abort
function)
SIGFPE
Error during an arithmetic operation (can be caused by division by zero or overflow)
SIGILL
Invalid instruction
SIGINT
Interrupt
SIGSEGV
Invalid memory access
SIGTERM
Termination request
Functions
void (*signal(int sig , void (*func )(int))) (int);
where:
a signal
sig
a function
func
of typevoid
, which will be called by the program in the event that the specified signal sig is raisedthe function func is defined as a handler and manages the error
the return value of signal is a pointer to the previous handler (usually not used)
Pre-defined handlers
SIG_DFL
Default handling of the specified signal
SIG_ING
Specifies to ignore the specified signal
int raise(int sig);
It generates the signal sig
, passed as an argument.
Last updated