aboutsummaryrefslogtreecommitdiffstats
path: root/libqpdf/QEXC.cc
blob: c65afbb6a0cd221aa79588bb6370c2c23bf339e9 (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
54
55
56
57
58
59
60
61
62
63
64
65
66
67

#include <qpdf/QEXC.hh>
#include <string.h>
#include <errno.h>

QEXC::Base::Base()
{
    // nothing needed
}

QEXC::Base::Base(std::string const& message) :
    message(message)
{
    // nothing needed
}

std::string const&
QEXC::Base::unparse() const
{
    return this->message;
}

void
QEXC::Base::setMessage(std::string const& message)
{
    this->message = message;
}

const char*
QEXC::Base::what() const throw()
{
    // Since unparse() returns a const string reference, its
    // implementors must arrange to have it return a reference to a
    // string that is not going to disappear.  It is therefore safe
    // for us to return it's c_str() pointer.
    return this->unparse().c_str();
}

QEXC::General::General()
{
    // nothing needed
}

QEXC::General::General(std::string const& message) :
    Base(message)
{
    // nothing needed
}

QEXC::System::System(std::string const& prefix, int sys_errno)
{
    // Note: using sys_errno in case errno is a macro.
    this->sys_errno = sys_errno;
    this->setMessage(prefix + ": " + strerror(sys_errno));
}

int
QEXC::System::getErrno() const
{
    return this->sys_errno;
}

QEXC::Internal::Internal(std::string const& message) :
    Base("INTERNAL ERROR: " + message)
{
    // nothing needed
}