// *** 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 #include #include #include 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