How to catch the system Exception SEGV

Hi all,

i wrote a small program which is throwing SEGV exception, in my program i can able to identify the error. But in general i want to catch the system related exception like SEGV and other exceptions through my C++ code.
Provide me some usefull links about it..
Can any one help me in how to catch these kind if system related exceptions?
man signal
man sigaction

http://www.linuxprogrammingblog.com/all-about-linux-signals?page=show

1
2
3
4
5
6
7
8
9
10
11
12
13
14

volatile sigatomic_t signum = 0;

void handle_signal( int signo ) {
    signum = signo;
}

int main() {
    signal( SIGSEGV, handle_signal );
    kill( getpid(), SIGSEGV );
    while( signum == 0 )
        usleep( 100 );
    cout << "received signal " << signum << endl;
}
Topic archived. No new replies allowed.