O
Old Wolf
1. What is the difference between #include <stdexcept>
and #include <exception> ?
2. Is there a list somewhere of what each standard exception is used
for? either to throw them, or throw user-defined exceptions
derived from them? (for example I have been deriving mine from
std::bad_alloc if there was a memory problem, or std::bad_exception
if there was some other problem)
3. Is it a good idea to make all user-defined exceptions derive from
std::exception?
4. While trying to see why my "catch (std::exception &e)" did not catch
a bad boost::lexical_cast<>, I discovered that that function throws
an object derived from "std::bad_cast", but std::bad_cast is NOT
derived from std::exception. Are there any other "special case"
exceptions in the Standard Library that are not derived from
std::exception?
5. If you have a handler like:
catch(std::exception &e) { whatever }
and the exception is thrown like:
throw foo_exception("error occurred");
where foo_exception is derived from std::exception, will it be
caught? (The exception thrown is a temporary, and you can't bind
temporaries to non-const references).
and #include <exception> ?
2. Is there a list somewhere of what each standard exception is used
for? either to throw them, or throw user-defined exceptions
derived from them? (for example I have been deriving mine from
std::bad_alloc if there was a memory problem, or std::bad_exception
if there was some other problem)
3. Is it a good idea to make all user-defined exceptions derive from
std::exception?
4. While trying to see why my "catch (std::exception &e)" did not catch
a bad boost::lexical_cast<>, I discovered that that function throws
an object derived from "std::bad_cast", but std::bad_cast is NOT
derived from std::exception. Are there any other "special case"
exceptions in the Standard Library that are not derived from
std::exception?
5. If you have a handler like:
catch(std::exception &e) { whatever }
and the exception is thrown like:
throw foo_exception("error occurred");
where foo_exception is derived from std::exception, will it be
caught? (The exception thrown is a temporary, and you can't bind
temporaries to non-const references).