Note that there are some explanatory texts on larger screens.

plurals
  1. POQt/C++ Error handling
    text
    copied!<p>I've been doing a lot of research about handling errors with Qt/C++ and I'm still as lost as when I started. Maybe I'm looking for an easy way out (like other languages provide). One, in particular, provides for an unhandled exception which I use religiously. When the program encounters a problem, it throws the unhandled exception so that I can create my own error report. That report gets sent from my customers machine to a server online which I then read later.</p> <p>The problem that I'm having with C++ is that any error handling that's done has to be thought of BEFORE hand (think try/catch or massive conditionals). In my experience, problems in code are not thought of before hand else there wouldn't be a problem to begin with.</p> <p>Writing a cross-platform application without a cross-platform error handling/reporting/trace mechanism is a little scary to me.</p> <p>My question is: Is there any kind of Qt or C++ Specific "catch-all" error trapping mechanism that I can use in my application so that, if something does go wrong I can, at least, write a report before it crashes?</p> <p>Example:</p> <pre><code> class MainWindow: public QMainWindow { [...] public slots: void add_clicked(); } void MainWindow::add_clicked() { QFileDialog dlg(this, Qt::Sheet); QString filename = dlg.getOpenFileName(this); if(!filename.isEmpty()) { QStringList path = filename.split(QDir::separator()); QString file = path.at(path.count()); // Index out of range assertion. if(!lst_tables->openDatabase(filename)) { [...] } } } </code></pre> <p>I want this error to be caught as an unhandled exception AND the application to quit without showing the user the default crash window on Windows/Mac operating system. I just want it to quit nicely after writing the assertion message to a file, etc.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload