VJ wrote:
Salt_Peter wrote:
Can you see why its a bad idea to catch(...) as opposed to a specific
catch?
Why is it a bad idea to catch all?
It has some good uses
Consider the list of possible standard exceptions that might be thrown:
ios_base::failure
bad_alloc
bad_cast
logic_error
runtime_error
bad_exception
It would be a shame to catch any of these in a carch-all for obvious
reasons.
#include <iostream>
#include <stdexcept>
int main()
{
try {
// may throw
}
catch ( const std::logic_error & e ) {
std::cerr << "a logic_error was caught: ";
std::cerr << e.what() << std::endl;
}
catch ( const std::exception & e ) {
std::cerr << "a specific error was caught: ";
std::cerr << e.what() << std::endl;
}
catch ( ... ) {
std::cerr << "an undetermined error occurred\n";
}
}