File: exceptionptr.cc

package info (click to toggle)
c%2B%2B-annotations 10.6.0-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 10,536 kB
  • ctags: 3,247
  • sloc: cpp: 19,157; makefile: 1,521; ansic: 165; sh: 128; perl: 90
file content (77 lines) | stat: -rw-r--r-- 1,391 bytes parent folder | download | duplicates (2)
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
69
70
71
72
73
74
75
76
77
#include <future>
#include <iostream>
#include <string>
using namespace std;

int main()
try
{
    exception_ptr ep;

    if (ep == 0)
        cerr << "null ptr\n";

//    promise<int> p;

    try
    {
        try
        {
            throw 1;
        }
        catch (...)
        {
            auto ep = current_exception();
            if (ep == 0)
                cerr << "current_exc. equals null if an int is thrown\n";
            rethrow_exception(ep);
        }
    }
    catch (int x)
    {
        cerr << "CAUGHT " << x << '\n';
    }
    catch (...)
    {
        cerr << "catch all\n";
    }

    ep = make_exception_ptr(exception());
    exception_ptr e2(ep);

    e2 = ep;

    if (ep == e2)
        cerr << "equal exc. ptrs\n";

    e2 = move(ep);

    if (ep != e2)
        cerr << "after move: unequal exc. ptrs\n";

    if (ep == 0)
        cerr << "after move: the rhs is 0\n";

//    p.set_exception(make_exception_ptr(exception()));
//    p.set_exception(make_exception_ptr(12));
//    p.set_exception(make_exception_ptr(string("hello")));

    rethrow_exception(make_exception_ptr(12));

}
catch (int x)
{
    cerr << "caught " << x << '\n';
}
catch (exception const &e)
{
    cerr << "caught exception object: " << e.what() << "\n";
}
catch (string const  &s)
{
    cerr << "caught string object\n";
}
catch (...)
{
    cerr << "caught unspecified exception\n";
}