This is really a rather specialised case. It is not a substitute for proper error checking and handling.
Code:
#include <stdio.h>
#include <stdlib.h>
#include <setjmp.h>
#include <signal.h>
sigjmp_buf env;
void func1 ( void ) {
printf("func1 dies\n");
{
int *p = NULL;
*p = 0;
}
printf("Never reached\n");
}
void func2 ( void ) {
printf("Now func2 carries on\n");
}
void catcher ( int sig ) {
if ( sig == SIGSEGV ) {
siglongjmp(env,1);
}
}
int main ( ) {
signal(SIGSEGV,catcher);
if ( sigsetjmp(env,SIGSEGV) == 0 ) {
func1();
} else {
func2();
}
}
$ gcc -D_POSIX_C_SOURCE bar.c
$ ./a.out
func1 dies
Now func2 carries on
I'll leave you to RTM on all the functions, so you know what all the traps and pitfalls are