|
@@ -1334,168 +1334,3 @@ void PrintStackReport()
|
|
|
#endif
|
|
|
queryLogMsgManager()->flushQueue(10*1000);
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
-#ifdef SIGNAL_TO_EXCEPTION
|
|
|
-
|
|
|
-/*static*/jmp_buf SignalToException::s_jmpbuf;
|
|
|
-/*static*/bool SignalToException::s_bUnixTrapHandlerSet = false;
|
|
|
-
|
|
|
-SignalToException::SignalToException()
|
|
|
-{
|
|
|
- if (!s_bUnixTrapHandlerSet)
|
|
|
- setUnixTrapHandler();
|
|
|
-
|
|
|
- memcpy(&m_old_jmpbuf,&s_jmpbuf,sizeof(jmp_buf));
|
|
|
-}
|
|
|
-
|
|
|
-SignalToException::~SignalToException()
|
|
|
-{
|
|
|
- memcpy(&s_jmpbuf,&m_old_jmpbuf,sizeof(jmp_buf));
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
-/*static*/
|
|
|
-void SignalToException::UnixTrapHandler(int sig)
|
|
|
-{
|
|
|
- longjmp(SignalToException::s_jmpbuf, sig);
|
|
|
-}
|
|
|
-
|
|
|
-/*static*/
|
|
|
-void SignalToException::setUnixTrapHandler()
|
|
|
-{
|
|
|
- struct sigaction action;
|
|
|
- sigemptyset(&action.sa_mask);
|
|
|
- action.sa_flags = 0;
|
|
|
- action.sa_handler = UnixTrapHandler;
|
|
|
-
|
|
|
- int signals[] = {SIGSEGV, SIGILL, SIGFPE, SIGPIPE, SIGSYS};
|
|
|
- for (int i = 0; i < sizeof(signals)/sizeof(signals[0]); i++)
|
|
|
- if ( sigaction(signals[i], &action, NULL) == -1)
|
|
|
- perror("sigaction failed while setting UnixTrapHandler");
|
|
|
-
|
|
|
- s_bUnixTrapHandlerSet = true;
|
|
|
-}
|
|
|
-
|
|
|
-/*static*/
|
|
|
-void SignalToException::processSetJmpResult(int res)
|
|
|
-{
|
|
|
- if (res != 0)
|
|
|
- {
|
|
|
- StringBuffer buf("throwing SIG");
|
|
|
- switch (res)
|
|
|
- {
|
|
|
- case SIGSEGV: buf.append("SEGV");
|
|
|
- break;
|
|
|
- case SIGILL : buf.append("ILL" );
|
|
|
- break;
|
|
|
- case SIGFPE : buf.append("FPE" );
|
|
|
- break;
|
|
|
- case SIGPIPE: buf.append("PIPE");
|
|
|
- break;
|
|
|
- case SIGSYS : buf.append("SYS" );
|
|
|
- break;
|
|
|
- default: buf.append("NAL ").append(res);
|
|
|
- break;
|
|
|
- }
|
|
|
- buf.append(" as exception");
|
|
|
- throw MakeStringException(res, "%s", buf.toCharArray());
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-#ifdef TEST_SIGNAL_TO_EXCEPTION
|
|
|
-
|
|
|
-int main(int argc, char**argv)
|
|
|
-{
|
|
|
-
|
|
|
- TRY
|
|
|
- {
|
|
|
- TRY
|
|
|
- {
|
|
|
- //generate SIGSEGV
|
|
|
- int* p=0;
|
|
|
- *p = 0;
|
|
|
- cout << "Next stmt in inner block!" << endl;
|
|
|
- }
|
|
|
- CATCH(...)
|
|
|
- {
|
|
|
- cout << "inner catch (...)" << endl;
|
|
|
- }
|
|
|
- ENDCATCH;
|
|
|
-
|
|
|
- //generate SIGFPE
|
|
|
- int p=0;
|
|
|
- int q=2/p;
|
|
|
- cout << "Next stmt in outer block!" << endl;
|
|
|
- }
|
|
|
- CATCH (char*)
|
|
|
- {
|
|
|
- }
|
|
|
- AND_CATCH(...)
|
|
|
- {
|
|
|
- cout << "outer catch (...)" << endl;
|
|
|
- }
|
|
|
- END_CATCH
|
|
|
-
|
|
|
- return 0;
|
|
|
-}
|
|
|
-#endif //TEST_SIGNAL_TO_EXCEPTION
|
|
|
-#endif //SIGNAL_TO_EXCEPTION
|
|
|
-
|
|
|
-#ifdef _TEST
|
|
|
-
|
|
|
-void raise1()
|
|
|
-{
|
|
|
- throw MakeStringException(-1,"test 1");
|
|
|
-}
|
|
|
-
|
|
|
-void raise2()
|
|
|
-{
|
|
|
- throw MakeOsException(3);
|
|
|
-}
|
|
|
-
|
|
|
-class DefaultExceptionHandler
|
|
|
-{
|
|
|
- unexpected_handler old;
|
|
|
-public:
|
|
|
- static void handler()
|
|
|
- {
|
|
|
- try {
|
|
|
- throw;
|
|
|
- }
|
|
|
- catch (IException *e) {
|
|
|
- StringBuffer s;
|
|
|
- e->errorMessage(s);
|
|
|
- printf("Unhandled Exception (%d): %s\n",e->errorCode(),(const char *)s.toCharArray());
|
|
|
- e->Release();
|
|
|
- }
|
|
|
- }
|
|
|
- DefaultExceptionHandler() { old = set_terminate(handler); }
|
|
|
- ~DefaultExceptionHandler() { set_terminate(old); }
|
|
|
-} _DefaultExceptionHandler;
|
|
|
-
|
|
|
-int main()
|
|
|
-{
|
|
|
- try {
|
|
|
- raise1();
|
|
|
- }
|
|
|
- catch (IException *e) {
|
|
|
- StringBuffer s;
|
|
|
- e->errorMessage(s);
|
|
|
- printf("exception %d '%s'\n",e->errorCode(),(const char *)s.toCharArray());
|
|
|
- e->Release();
|
|
|
- }
|
|
|
- try {
|
|
|
- raise2();
|
|
|
- }
|
|
|
- catch (IException *e) {
|
|
|
- StringBuffer s;
|
|
|
- e->errorMessage(s);
|
|
|
- printf("exception %d '%s'\n",e->errorCode(),(const char *)s.toCharArray());
|
|
|
- e->Release();
|
|
|
- }
|
|
|
- raise1();
|
|
|
- return 0;
|
|
|
-}
|
|
|
-
|
|
|
-#endif
|