How to catch exceptions in a QThread?

You want to catch system exceptions outside the main thread. In the main thread everything is very simple:
Override QApplication::notify (), and rejoice:
bool notify(QObject *obj, QEvent *ev)
{
 bool result = false;
try{
 result = QApplication::notify(obj, ev);
 } catch(...){
 qDebug() << "exception";
 result = false;
}
 return result;
}


As a test used the following code (event clicking on QPushButton):
void MainWindow::on_pb1_clicked()
{
 QObject* obj = (QObject*) 0x00112233;
 delete obj;
}

All works well when you specify compile options -EHa. But there is one problem. If you use QThread, this design does not work. Example:
Override function on_pb1_clicked():
void MainWindow::on_pb1_clicked()
{
QPluginLoader pluginLoader("d:/Sources/qt/_BUILDS/Plugin/Desktop_Qt_5_5_1_MSVC2013_64bit/release/FirstPlugin.dll");
 QObject *pluginObj = pluginLoader.instance();
 if (pluginObj){
 CensorPluginRootInstance* root = qobject_cast<censorpluginrootinstance *>(pluginObj);
 if (root) {
 PluginInterface* plugin = root->createPluginObject();
 if (plugin){
 ui->teStat->append("plugin load ok!");
 QThread* thread = new QThread;
 connect(thread, &QThread::started, plugin, &PluginInterface::Work);
plugin->moveToThread(thread);
thread->start();
 } else
 ui->teStat->append("plugin not loaded 3!");
}else
 ui->teStat->append("plugin not loaded 2!");
}else
 ui->teStat->append("plugin 1 is not loaded!");
}</censorpluginrootinstance>

Plugin code:
bool Plugin::Work()
{
 char* pc = (char*)0x00112233;
 delete pc;
 return false;
}

The plugin is loaded, as evidenced by the inscription "plugin load ok!", and then:
f76d61c04cdc4a3ebbcd2d46e9415b0e.png
How to programmatically catch exceptions caused by not from the main thread?
July 9th 19 at 10:19
1 answer
July 9th 19 at 10:21
Its function pass inside the plugin call with the interception,

Movetothread, what is it?

Still have the debugger symbols.
Have you used Qt? - kip.Runolfsson64 commented on July 9th 19 at 10:24
Nah - mercedes commented on July 9th 19 at 10:27
:
moveToThread is the transfer of the object to another thread (thread) in the framework of Qt. - kip.Runolfsson64 commented on July 9th 19 at 10:30
: the wording is frightening. at leisure I will look qt like I have even installed Google also offers to do the override run or something, the effect is the same . Just to avoid collapse of the program? Tried already something? - mercedes commented on July 9th 19 at 10:33
: Yes, the goal is not to collapse the program, possibly indicating the problem areas. While trying different methods from the try{}catch(...){} to signal(SIGTERM,handler), but so far the result is negative. - kip.Runolfsson64 commented on July 9th 19 at 10:36
Show the code with TRAIstackoverflow.com/questions/7049502/c-try-and-try-...

I think Richter was something on this subject, but I could be wrong, I don't remember making a C++ try catch,in you may have to use__try , again not sure. For problem areas should be a pdb(symbols).to rebuild with symbols plugin can be? - mercedes commented on July 9th 19 at 10:39
Without symbols, the call stack will still be.. - mercedes commented on July 9th 19 at 10:42

Find more questions by tags QtC++