Can i use "try catch" in app?
I try to write a simple example ,in app I use "try catch" but unsuccess?
Can i help you?
Can i use "try catch" in app?
I try to write a simple example ,in app I use "try catch" but unsuccess?
Can i help you?
Show us what you tried so far.
i tried
Qt Code:
int t =1; int t1 = 0; try { float t2 = t/t1; } catch (...) { qDebug()<<"test"; }To copy to clipboard, switch view to plain text mode
and what happens?
app is wrong. why try catch do not active?
what means "app is wrong"?
app is quit and it does not run command "Qdebug()<<"test"
What compiler are you using? I think in some cases, the compiler doesn't generate an exception
Division by zero doesn't throw an exception in Standard C++.
if Qt does not catch exceptions, it will crashes...
so, does Qt catch exceptions anywhere?
what does Qt have to do with this? it's c++ that does not throw an exception in this case, as helloworld stated.
you can use try...catch in your qt app. you can catch exceptions. but you can't catch exceptions that are never thrown...
Floating point errors don't throw exceptions. They generate signals. Not Qt signals.
If you need to respond to them, you need to install your own system signal handler. See the C++ signal() call for information on how to do this.
If all you want to do is avoid division by zero, simply check that the divisor is not equal to zero before performing the operation, and either throw your own exception or put your own error handling in place.
Thanks all for reply
I only want to do is avoid app crashes by catch unforeseen error
Bookmarks