I was trying to handle exceptions in few functions and forgot to add a try-catch block in one of them, that's why my app crashed with "Microsoft Visual C++ Runtime Library:blah blah".My working sample now looks like this:
class myException: public QtConcurrent::Exception {
public:
myException(const char *desc) {
excdesc = desc;
}
const char *excdesc;
};
class myException: public QtConcurrent::Exception {
public:
myException(const char *desc) {
excdesc = desc;
}
const char *excdesc;
};
To copy to clipboard, switch view to plain text mode
and a part of one function
try {
//some other code...
int b = 0;
if (b == 0) {
myException exc("you can not divide with 0");
throw exc;
}
} catch (myException & e) {
QMessageBox::critical(this,tr
("Warning"),tr
(e.
excdesc));
}
try {
//some other code...
int b = 0;
if (b == 0) {
myException exc("you can not divide with 0");
throw exc;
}
} catch (myException & e) {
QMessageBox::critical(this,tr("Warning"),tr(e.excdesc));
}
To copy to clipboard, switch view to plain text mode
which works ok, however I see little point have an extra class myException for as little as showing a simple error description. Couldn't I do just something like this:
try {
//some other code...
int b = 0;
if (b == 0) {
throw "you can not divide with 0";
}
} catch (char *e) {
}
try {
//some other code...
int b = 0;
if (b == 0) {
throw "you can not divide with 0";
}
} catch (char *e) {
QMessageBox::critical(this,tr("Warning"),tr(e));
}
To copy to clipboard, switch view to plain text mode
but my app crashes this way. Please suggest, thanks.
Bookmarks