Exceptions: Difference between revisions

Content added Content deleted
(→‎Defining exceptions: std::exception as base class, and a note)
(→‎Catching exceptions: another catch clause for std::exception)
Line 210: Line 210:


===Catching exceptions===
===Catching exceptions===
<cpp>
try {
try {
foo();
foo();
Line 216: Line 217:
{
{
// handle exceptions of type MyException and derived
// handle exceptions of type MyException and derived
}
catch (std::exception &exc)
{
// handle exceptions derived from std::exception, which were not handled by above catches
// e.g.
std::cerr << exc.what() << std::endl;
}
}
catch (...)
catch (...)
Line 221: Line 228:
// handle any type of exception not handled by above catches
// handle any type of exception not handled by above catches
}
}
</cpp>


=={{header|C sharp|C #}}==
=={{header|C sharp|C #}}==