Show how to create a user-defined exception and show how to catch an exception raised from several nested calls away.
- Create two user-defined exceptions, U0 and U1.
- Have function foo call function bar twice.
- Have function bar call function baz.
- Arrange for function baz to raise, or throw exception U0 on its first call, then exception U1 on its second.
- Function foo should catch only exception U0, not U1.
Show/describe what happens when the program is run.
First exception will be caught and message will be displayed, second will be caught by the default exception handler, which as required by the C++ Standard, will call terminate(), aborting the task, typically with an error message.
Exception U0 caught This application has requested the Runtime to terminate it in an unusual way.
The exact behavior for an uncaught exception is implementation-defined.
Content is available under GNU Free Documentation License 1.2.