Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Special Interest Groups
  3. C++ Gurus
  4. How to catch unhanded exception ?
Forum Updated to NodeBB v4.3 + New Features

How to catch unhanded exception ?

Scheduled Pinned Locked Moved C++ Gurus
7 Posts 4 Posters 6.5k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Anticross
    wrote on last edited by
    #1

    I've got QCoreApplication. I run it at Microsoft Windows OS and need to catch unhanded exception. I try to do this:
    @try{
    m_defMail.setDefault();
    #ifdef _DEBUG
    m_defMail.setDebugDefault();
    #endif

    // int g = 0;
    // int t = g/g;

    initPathes();
    initArgs();
    analyseArguments(argc, argv);
    sendAllMessages();
    }
    catch (...){
    qDebug() << "sxMailSender: Unhanded Exception!!! Application will be terminated.";
    }--@
    but it's have no effect.

    Edit: moved to C++, as it is no Qt related topic. Gerolf

    1 Reply Last reply
    0
    • G Offline
      G Offline
      giesbert
      wrote on last edited by
      #2

      which exception do you try to catch?
      There are two types:

      • "normal" exception (by throw) which can be caught by try/catch
      • structured exceptions (like div 0, null pointer, etc.) which can't be catched by try/catch. For those you need try/except which is not possible in functions using C++ objects :-( Then you need an exception translator (_set_se_translator). There you can convert the structured exception into a C++ exception and throw that one. But sorry,. I can't give you code for that, as it is closed source what I do here.

      Nokia Certified Qt Specialist.
      Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

      1 Reply Last reply
      0
      • A Offline
        A Offline
        Anticross
        wrote on last edited by
        #3

        @try{
        m_defMail.setDefault();
        #ifdef _DEBUG
        m_defMail.setDebugDefault();
        #endif

        int g = 0;
        int t = g/g;

        initPathes();
        initArgs();
        analyseArguments(argc, argv);
        sendAllMessages();
        }
        catch (...){
        qDebug() << "sxMailSender: Unhanded Exception!!! Application will be terminated.";
        }--@

        I mean for example in this source i try to catch div by zero. But I can't reach catch section and get OS exception message. So I need some how to catch all OS exceptions for my application.

        1 Reply Last reply
        0
        • G Offline
          G Offline
          giesbert
          wrote on last edited by
          #4

          Did you read my post completely?

          bq. structured exceptions (like div 0, null pointer, etc.) which can’t be catched by try/catch.

          Therefore you need structured exception handling or exception translation.

          Nokia Certified Qt Specialist.
          Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

          1 Reply Last reply
          0
          • M Offline
            M Offline
            maxim.prishchepa
            wrote on last edited by
            #5

            Also you can use flag /EHa if you use compiler from Microsoft (description this flag you can find in "MSDN":http://msdn.microsoft.com/en-us/library/1deeycx5(v=vs.80).aspx

            Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz).

            1 Reply Last reply
            0
            • G Offline
              G Offline
              giesbert
              wrote on last edited by
              #6

              /EHa does enable structured exception handling. It does not enable try/catch for structured exceptions.

              Nokia Certified Qt Specialist.
              Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

              1 Reply Last reply
              0
              • J Offline
                J Offline
                jdarnold
                wrote on last edited by
                #7

                I use the Windows ::SetUnhandledExceptionFilter API:

                @
                ....
                ::SetUnhandledExceptionFilter( IGExceptionHandler );
                ...

                #if defined(WIN32)
                LONG WINAPI IGExceptionHandler( struct _EXCEPTION_POINTERS pExceptionInfo )
                {
                DWORD code = pExceptionInfo->ExceptionRecord->ExceptionCode;
                IGLog( qDebug(), "Handling Visimeet Exception : " << code << " Address: " << pExceptionInfo->ExceptionRecord->ExceptionAddress);
                if ( code == STATUS_ACCESS_VIOLATION )
                { // add this bit o' info
                IGLog( qDebug(), "
                *** ACCESS VIOLATION ")
                }
                else if ( code == STATUS_ILLEGAL_INSTRUCTION )
                {
                IGLog( qDebug(), "
                ILLEGAL INSTRUCTION ");
                }
                else if ( code == STATUS_FLOAT_DIVIDE_BY_ZERO || code == STATUS_INTEGER_DIVIDE_BY_ZERO )
                {
                IGLog( qDebug(), "
                DIVIDE BY ZERO ");
                }
                else if ( code == IGLOGGER_FATAL_ERROR )
                { // our interanl error if qFatal is used
                IGLog( qDebug(), "
                Qt FATAL ERROR ")
                }
                else
                {
                IGLog( qDebug(), "
                Unknown Fatal Error ****");
                }

                LONG retval = EXCEPTION_EXECUTE_HANDLER;
                
                visiqt->sendReport(true);
                
                return retval;
                

                }
                @

                1 Reply Last reply
                0

                • Login

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved