the simple code below
// g++ centro.cc -o centro
#include <iostream>
using namespace std;
int main(int argc, char *argv[])
{
try
{
cout << "Going to throw" << endl;
throw;
}
catch(...)
{
cout << "An exception occurred" << endl;
}
return 0;
}
produces an abort:
Going to throw
terminate called without an active exception
Aborted (core dumped)
I don't understand what's wrong, can anybody point me in the right direction?
In general, wrapping your Java code with try/catch blocks doesn't have a significant performance impact on your applications. Only when exceptions actually occur is there a negative performance impact, which is due to the lookup the JVM must perform to locate the proper handler for the exception.
Still, there are some situations where the existence of a try/catch block may prevent optimizations which--but for the try/catch--would have allowed code to run faster. Save this answer. Show activity on this post. Yes, try/catch will "hurt" performance (everything is relative).
Originally Answered: Does using "try and catch" in programming makes the run of the code slower? Yes, the mechanism added in try ..
Try thowing something. You aren't throwing any exception.
throw;
itself is generally used to re-throw the same exception inside a catch
block.
Compare the result with throw "something";
or perhaps an instance of std::exception
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With