Try & Catch in QApplication
I try to manage the exception of my classes, and i put this “Throw” in the constructor.
- line::line(point A, point B):a(A), b(B){
- if (a==b) {throw coincidentPointLine();}
- }
This is in the logical part of the my project and there’s no Qt object of function in this class.
And this is a slot of my QMainWindow:
- void mainWindow::on_twoPointLineButton_clicked(){
- //get the input line
- std::string input = Qinput.toStdString();
- line* L;
- try{L = new line(GUIUtilities::getInputLine(input));}
- catch (coincidentPointLine()){
- std::cout<<"error";
- abort();}
- function F = L->lineEquatioon();
- std::string result = F.get[removed]);
- this->setResult(result);
- }
It’s look like it woks but doesn’t! The compiler return this error!
*Qt has caught an exception thrown from an event handler. Throwing
exceptions from an event handler is not supported in Qt. You must
reimplement QApplication::notify() and catch all exceptions there.*
How i can resolve this problem?
I read about QApplication::notify(), but i don’t understand very well…
4 replies
You better change your code to not throw from the constructor. How do you reclaim the memory used by a object that threw in its constructor? It is not constructed yet, so there is no object. There is nothing you can call the destructor on.
See e.g. http://herbsutter.com/2008/07/25/constructor-exceptions-in-c-c-and-java/
You must log in to post a reply. Not a member yet? Register here!



