File: defaultcatch.yo

package info (click to toggle)
c%2B%2B-annotations 13.02.02-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 13,576 kB
  • sloc: cpp: 25,297; makefile: 1,523; ansic: 165; sh: 126; perl: 90; fortran: 27
file content (31 lines) | stat: -rw-r--r-- 1,838 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
At a certain level of the program only a limited set of handlers may actually
be required. Exceptions whose types belong to that limited set are processed,
all other exceptions are passed on to exception handlers of an outer level
tt(try) block.

An intermediate type of exception handling may be implemented using the
default exception handler, which must be (due to the hierarchal nature of
exception catchers, discussed in section ref(EXCEPTIONCATCH)) placed beyond
all other, more specific exception handlers.

This default exception handler cannot determine the actual type of the thrown
exception and cannot determine the exception's value but it may execute some
statements, and thus do some default processing. Moreover, the caught
exception is not lost, and the default exception handler may use the empty
tt(throw) statement (see section ref(EMPTYTHROW)) to pass the exception on to
an outer level, where it's actually processed.  Here is an example showing
this use of a default exception handler:
    verbinclude(-a examples/defaultcatch.cc)
    The program's output illustrates that an empty tt(throw) statement in a
default exception handler throws the received exception to the next (outer)
level of exception catchers, keeping type and value of the thrown exception.

Thus, basic or generic exception handling can be accomplished at an inner
level, while specific handling, based on the type of the thrown expression,
can be provided at an outer level. Additionally, particularly in
multi-threaded programs (cf. chapter ref(THREADING)), thrown exceptions can be
transferred between threads after converting tt(std::exception) objects to
tt(std::exception_ptr) objects. This proceduce can even be used from inside
the default catcher. Refer to section ref(EXCPTR) for further coverage of the
class tt(std::exception_ptr).