Menu

Catch non-std::exceptions in PythonQtCallSlot

Tonka
2017-04-18
2017-04-18
  • Tonka

    Tonka - 2017-04-18

    Hey Florian,

    I have seom "problems" with non-std::exceptions in PythonQtCallSlot. I know that it is not possible for you to catch non-std::exception with the correct message, but you can catch all other exception with a default message instead of a crash from the application (because no one is catching it). The fix is really simple.

    SVN revision 446, PythonQtSlot.cpp
    existing code Line 203

    } catch (std::exception& e) {
            hadException = true;
            QByteArray what("std::exception: ");
            what += e.what();
            PyErr_SetString(PyExc_RuntimeError, what.constData());
          }
    

    Patched code:

          } catch (std::exception& e) {
            hadException = true;
            QByteArray what("std::exception: ");
            what += e.what();
            PyErr_SetString(PyExc_RuntimeError, what.constData());
          } catch(...)
          {
            hadException = true;
            QByteArray what("unknown internal exception");
            PyErr_SetString(PyExc_RuntimeError, what.constData());
          }
    

    The catch(...) will catch all other exception with a default message, which is enough to be able to catch the exception in the py-script. The scripter will get a default message, but he/she is able to catch it in script instead of a crash.

    Hope you like the "patch"

    Greetings
    Tonka

     
  • Florian Link

    Florian Link - 2017-04-18

    I added a catch (...) which is enabled by default.
    It can be disabled in the src.pro file by undefining PYTHONQT_CATCH_ALL_EXCEPTIONS.

     
  • Tonka

    Tonka - 2017-04-18

    Nice. Thx

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.