File: try.yo

package info (click to toggle)
c%2B%2B-annotations 12.2.0-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 13,044 kB
  • sloc: cpp: 24,337; makefile: 1,517; ansic: 165; sh: 121; perl: 90
file content (24 lines) | stat: -rw-r--r-- 1,165 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
The ti(try)-block surrounds tt(throw) statements. Remember that a program is
always surrounded by a global tt(try) block, so tt(throw) statements may
appear anywhere in your code. More often, though, tt(throw) statements are
used in function bodies and such functions may be called from within tt(try)
blocks.

A tt(try) block is defined by the keyword tt(try) followed by a compound
statement. This block, in turn,  em(must) be followed by at least one
tt(catch) handler:
        verb(    try
    {
                // any statements here
    }
    catch(...)  // at least one catch clause here
    {})

tt(Try)-blocks are commonly nested, creating exception em(levels). For
example, tt(main)'s code is surrounded by a tt(try)-block, forming an outer
level handling exceptions.  Within tt(main)'s tt(try)-block functions are
called which may also contain tt(try)-blocks, forming the next exception
level. As we have seen (section ref(EMPTYTHROW)), exceptions thrown in
inner level tt(try)-blocks may or may not be processed at that level. By
placing an empty tt(throw) statement in an exception handler, the
thrown exception is passed on to the next (outer) level.