File: futureerrc.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 (68 lines) | stat: -rw-r--r-- 3,200 bytes parent folder | download | duplicates (4)
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
Members of the class tt(std::future) may return errors by throwing
tt(std::future_error) exceptions. These error conditions are represented by
the values of the strongly typed enumeration
    hi(future_errc)tt(std::future_errc) which defines the following symbolic
constants:
    itemization(
    iti(broken_promise)
        quote( 
   tt(Broken_promise) is thrown when a tt(future) object was received whose
    value was never assigned by a tt(promise) or tt(packaged_task). For
    example, an object of the class tt(promise<int>) should set the value of
    the tt(future<int>) object returned by its tt(get_future) member
    (cf. section ref(PROMISE)), but if it doesn't do so, then a
    tt(broken_promise) exception is thrown, as illustrated by the following
    program:
   verbinclude(-n //code examples/brokenpromise.cc)
   At line 3 a tt(promise) object is created, but its value is never
    set. Consequently, it `breaks its promise' to produce a value: when
    tt(main) tries to retrieve its value (in line 9) a tt(std::futue_error)
    exception is thrown containing the tt(future_errc::broken_promise)
    value)

    iti(future_already_retrieved) 
        quote(
   tt(Future_already_retrieved) is thrown when multiple attempts are made to
    retrieve the tt(future) object from, e.g., a tt(promise) or
    tt(packaged_task) object that (eventually) should be ready. For example:
   verbinclude(-n //code examples/alreadyretrieved.cc)
   Note that after defining the tt(std::promise) object in line 3 it has
    merely been defined: no value is ever assigned to its tt(future). Even
    though no value is assigned to the tt(future) object, it em(is) a valid
    object. I.e., after some time the future em(should) be ready, and the
    future's tt(get) member should produce a value. Hence, line 4 succeeds,
    but then, in line 5, the exception is thrown as `the future has already
    been retrieved'.)

    iti(promise_already_satisfied) 
        quote(
   tt(Promise_already_satisfied) is thrown when multiple attempts are made to
    assign a value to a tt(promise) object. Assigning a value or
    tt(exception_ptr) to the tt(future) of a tt(promise) object may happen
    only once.  For example:
   verbinclude(-n //code examples/promisealreadysatisfied.cc)
        )

    iti(no_state) 
        quote(
   tt(No_state) is thrown when a member function (other than tt(valid), see
    below) of a tt(future) object is called when its tt(valid) member returns
    tt(false). This happens, e.g., when calling members of a default
    constructed tt(future) object. tt(No_state) is not thrown for tt(future)
    objects returned by the tt(async) factory function or returned by the
    tt(get_future) members of tt(promise) or tt(packaged_task) type
    of objects. Here is an example:
   verbinclude(-n //code examples/nostate.cc)
        )
    )

The class   hi(future_error)tt(std::future_error) is derived from the class
tt(std::exception), and offers, in addition to the tt(char const *what()
const) member also the member hi(code)tt(std::error_code const &code() const),
returning an hi(error_code)tt(std::error_code) object associated
with the thrown exception.