aboutsummaryrefslogtreecommitdiffstats
path: root/libtests/qexc.cc
blob: 6a89f68df3ee815a3a699244558810fc7a24007e (plain) (blame)
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

#include <qpdf/QEXC.hh>
#include <iostream>
#include <errno.h>
#include <stdlib.h>

void f(int n)
{
    switch (n)
    {
      case 0:
	throw QEXC::General("general exception");
	break;

      case 1:
	throw QEXC::Internal("internal error");
	break;

      case 2:
	throw QEXC::System("doing something", EINVAL);
	break;
    }
}

int main(int argc, char* argv[])
{
    if (argc != 2)
    {
	std::cerr << "usage: qexc n" << std::endl;
	exit(2);
    }

    try
    {
	f(atoi(argv[1]));
    }
    catch (QEXC::General& e)
    {
	std::cerr << "exception: " << e.unparse() << std::endl;
	std::cerr << "what: " << e.what() << std::endl;
	exit(2);
    }
    catch (std::exception& e)
    {
	std::cerr << "uncaught exception: " << e.what() << std::endl;
	exit(3);
    }
    catch (...)
    {
	exit(4);
    }
    return 0;
}