paludis
Version 3.0.2
The one true package mangler
paludis
util
exception.hh
Go to the documentation of this file.
1
/* vim: set sw=4 sts=4 et foldmethod=syntax : */
2
3
/*
4
* Copyright (c) 2005, 2006, 2007, 2008 Ciaran McCreesh
5
*
6
* This file is part of the Paludis package manager. Paludis is free software;
7
* you can redistribute it and/or modify it under the terms of the GNU General
8
* Public License version 2, as published by the Free Software Foundation.
9
*
10
* Paludis is distributed in the hope that it will be useful, but WITHOUT ANY
11
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
13
* details.
14
*
15
* You should have received a copy of the GNU General Public License along with
16
* this program; if not, write to the Free Software Foundation, Inc., 59 Temple
17
* Place, Suite 330, Boston, MA 02111-1307 USA
18
*/
19
20
#ifndef PALUDIS_GUARD_PALUDIS_EXCEPTION_HH
21
#define PALUDIS_GUARD_PALUDIS_EXCEPTION_HH 1
22
23
#include <
paludis/util/attributes.hh
>
24
#include <exception>
25
#include <memory>
26
#include <string>
27
28
/** \file
29
* Declaration for the Exception base class, the InternalError exception
30
* class, the NameError class and related utilities.
31
*
32
* \ingroup g_exceptions
33
*
34
* \section Examples
35
*
36
* - None at this time.
37
*/
38
39
namespace
paludis
40
{
41
/**
42
* Backtrace context class.
43
*
44
* \ingroup g_exceptions
45
* \nosubgrouping
46
*/
47
class
PALUDIS_VISIBLE
Context
48
{
49
private
:
50
Context(
const
Context &);
51
const
Context & operator= (
const
Context &);
52
53
public
:
54
///\name Basic operations
55
///\{
56
57
Context(
const
std::string &);
58
59
~Context()
noexcept
(
false
);
60
61
///\}
62
63
/**
64
* Current context.
65
*/
66
static
std::string
backtrace
(
const
std::string & delim);
67
};
68
69
/**
70
* Base exception class.
71
*
72
* \ingroup g_exceptions
73
* \nosubgrouping
74
*/
75
class
PALUDIS_VISIBLE
Exception :
76
public
std::exception
77
{
78
private
:
79
const
std::string _message;
80
mutable
std::string _what_str;
81
struct
ContextData;
82
const
std::unique_ptr<ContextData> _context_data;
83
84
const
Exception & operator= (
const
Exception &);
85
86
protected
:
87
///\name Basic operations
88
///\{
89
90
Exception(
const
std::string &
message
)
noexcept
;
91
92
Exception(
const
Exception &);
93
94
///\}
95
96
public
:
97
///\name Basic operations
98
///\{
99
100
~Exception()
override
;
101
102
///\}
103
104
/**
105
* Return our descriptive error message.
106
*/
107
const
std::string &
message
() const noexcept;
108
109
/**
110
* Make a backtrace.
111
*/
112
std::
string
backtrace
(const std::
string
& delim) const;
113
114
/**
115
* Is our backtrace empty?
116
*/
117
bool
empty
() const;
118
119
/**
120
* A better what, if possible.
121
*/
122
const
char
*
what
() const noexcept override;
123
};
124
125
/**
126
* An InternalError is an Exception that is thrown if something that is
127
* never supposed to happen happens.
128
*
129
* \ingroup g_exceptions
130
* \nosubgrouping
131
*/
132
class
PALUDIS_VISIBLE
InternalError
:
133
public Exception
134
{
135
public
:
136
/**
137
* Constructor.
138
*
139
* \param location Should be set to the PALUDIS_HERE macro.
140
*
141
* \param message A short message.
142
*/
143
InternalError
(
const
std::string & location,
const
std::string &
message
)
noexcept
;
144
};
145
146
/**
147
* A NotAvailableError is an Exception that is thrown if something that is
148
* not available (for example due to compile time configure options or platform
149
* limitations) is used.
150
*
151
* \ingroup g_exceptions
152
* \nosubgrouping
153
*/
154
class
PALUDIS_VISIBLE
NotAvailableError
:
155
public
Exception
156
{
157
public
:
158
/**
159
* Constructor.
160
*/
161
NotAvailableError
(
const
std::string &
message
)
noexcept
;
162
};
163
164
/**
165
* A NameError is an Exception that is thrown when some kind of invalid
166
* name is encountered.
167
*
168
* \ingroup g_exceptions
169
* \ingroup g_names
170
* \nosubgrouping
171
*/
172
class
PALUDIS_VISIBLE
NameError
:
173
public
Exception
174
{
175
protected
:
176
/**
177
* Constructor.
178
*
179
* \param name The invalid name encountered.
180
* \param role The role for the name, for example "package name".
181
*/
182
NameError
(
const
std::string & name,
const
std::string & role)
noexcept
;
183
184
/**
185
* Constructor.
186
*
187
* \param name The invalid name encountered.
188
* \param role The role for the name, for example "package name".
189
* \param msg Any extra message.
190
*/
191
NameError
(
const
std::string & name,
const
std::string & role,
192
const
std::string & msg)
noexcept
;
193
};
194
195
/**
196
* A ConfigurationError is thrown when an invalid configuration occurs.
197
*
198
* \ingroup g_exceptions
199
* \nosubgrouping
200
*/
201
class
PALUDIS_VISIBLE
ConfigurationError
:
202
public
Exception
203
{
204
public
:
205
/**
206
* Constructor.
207
*/
208
ConfigurationError
(
const
std::string & msg)
noexcept
;
209
};
210
211
/** \def PALUDIS_HERE
212
* Expands to the current function name, file and line, for use with
213
* paludis::InternalError.
214
*
215
* \ingroup g_exceptions
216
*/
217
#define PALUDIS_HERE (std::string(__PRETTY_FUNCTION__) + " at " + \
218
std::string(__FILE__) + ":" + paludis::stringify(__LINE__))
219
}
220
221
#endif
attributes.hh
paludis::ConfigurationError::ConfigurationError
ConfigurationError(const std::string &msg) noexcept
paludis::Context::backtrace
static std::string backtrace(const std::string &delim)
paludis::Exception::backtrace
std::string backtrace(const std::string &delim) const
paludis::Exception::what
const char * what() const noexcept override
paludis::Exception::message
const std::string & message() const noexcept
paludis::Exception::empty
bool empty() const
paludis::InternalError::InternalError
InternalError(const std::string &location, const std::string &message) noexcept
paludis::NameError::NameError
NameError(const std::string &name, const std::string &role, const std::string &msg) noexcept
paludis::NameError::NameError
NameError(const std::string &name, const std::string &role) noexcept
paludis::NotAvailableError::NotAvailableError
NotAvailableError(const std::string &message) noexcept
PALUDIS_VISIBLE
#define PALUDIS_VISIBLE
Definition
attributes.hh:59
paludis
Definition
about_metadata-fwd.hh:24
Generated by
1.18.0