Test for catching the SIGSEGV or SIGBUS without crashing and combined with try{}catch(){}.
433fc3dd738edd7c15e31f6955b42940c9811cbd42f2c5eeb0cdb4401538fd0a
// *** Synnergy Networks
// * Description:
//
// Test for catching the SIGSEGV or SIGBUS without crashing
// and combined with try{}catch(){}
// * Author:
//
// guidob (guidob@synnergy.net)
// Synnergy Networks (c) 1999, http://www.synnergy.net
// * Greets:
//
// Synnergy Networks, Hit2000 crew, Cindy
// * Comments:
//
// For more details, read the source.
// *** Synnergy Networks
#include <iostream.h>
#include <signal.h>
#include <stdlib.h>
#include <siginfo.h>
struct report {
int err;
int sig;
int critval;
} page1 = { 0, 0, 0 };
void notwithme(int);
int beyond(int);
int main(){
int i;
try{
sigset(SIGSEGV,notwithme);
sigset(SIGBUS,notwithme);
for(i=10000;;i++){
beyond(i);
cout << "Survifed beyond i = " << i << endl;
}
}
catch(report& seite1){
cout << "Yes we made it into the catch()" << endl;
cout << "seite1.err is: " << seite1.err << endl;
cout << "seite1.sig is: " << seite1.sig << endl;
cout << "seite1.critval is: " << seite1.critval << endl;
return(0);
}
catch(...){
cout << "Came to the second catch()" << endl;
return(1);
}
cout << "After the catch block" << endl;
return(1);
} // end of main()
int beyond(int i){
int a[50];
page1.critval = i;
// Main operation which causes an unforseen error
a[i]=1;
return(1);
}
void notwithme(int sig){
psignal(sig, "Function notwithme() got signal: ");
page1.err = 1;
page1.sig = sig;
throw page1;
return;
}
// EOF