File: example.yo

package info (click to toggle)
c%2B%2B-annotations 8.2.0-1
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 11,804 kB
  • ctags: 2,845
  • sloc: cpp: 15,418; makefile: 2,473; ansic: 165; perl: 90; sh: 29
file content (23 lines) | stat: -rw-r--r-- 1,125 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
In the following examples the same basic program is used. The program uses
two classes, tt(Outer) and tt(Inner).

    First, an tt(Outer) object is defined in tt(main), and its member
tt(Outer::fun) is called.  Then, in tt(Outer::fun) an tt(Inner) object is
defined. Having defined the tt(Inner) object, its member tt(Inner::fun) is
called.

That's about it. The function tt(Outer::fun) terminates calling
tt(inner)'s destructor. Then the program terminates, activating
tt(outer)'s destructor. Here is the basic program:
        verbinclude(exceptions/examples/basic.cc)
    After compiling and running, the program's output is entirely as expected:
the destructors are called in their correct order (reversing the calling
sequence of the constructors).

Now let's focus our attention on two variants in which we simulate a non-fatal
disastrous event in the tt(Inner::fun) function. This event must supposedly be
handled near tt(main)'s end.

We'll consider two variants. In the first variant the event is handled by
ti(setjmp) and ti(longjmp); in the second variant the event is handled using
bf(C++)'s exception mechanism.