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.
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.
Writing a cross-platform application without a cross-platform error handling/reporting/trace mechanism is a little scary to me.
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?
Example:
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))
{
[...]
}
}
}
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.
question from:
https://stackoverflow.com/questions/4661883/qt-c-error-handling 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…