|
|
 |
 |
 |
 |
Exception Handling
Hi, I was wondering if there is any way to catch exceptions without knowing in advance what errors may occur. What I mean to say is that is it possible to use try {} on a bunch of lines and catch ANY exception that might have occurred within those few lines without the program crashing first ? Thanks a ton, Speed.
On 4 Juni, 13:39, Speed <lostandha@gmail.com> wrote: > Hi, > I was wondering if there is any way to catch exceptions without > knowing in advance what errors may occur. > What I mean to say is that is it possible to use try {} on a bunch of > lines and catch ANY exception that might have occurred within those > few lines without the program crashing first ?
There are two options, if you know that all exceptions that might occur are subclasses of some common base-class (like std::exception) you can catch the common base-class: catch (std::exception& e) // Notice the & { std::cout << e.what() << std::endl; }
If that does not work you can use (...) to catch anything that is thrown, however if you do you can not get any information about it, not even the type: catch (...) { std::cout << "An error occured!" << std::end; }
-- Erik Wikstrm
Thanks a ton. But what do I need to throw in the try {}.
|
 |
 |
 |
 |
|