Debian Codegraph @

src/include/exception.h

raw
1 //
2 // Copyright (C) 2004-2006 Jasmine Langridge, [email protected]
3 // Copyright (C) 2015 Andrei Bondor, [email protected]
4 //
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 //
19
20 #pragma once
21
22 #include <exception>
23 #include <string>
24
25 class PException: public std::exception
26 {
27 public:
28
29 PException(const std::string &text):
30 text(text)
31 {
32 }
33
34 const char * what() const noexcept
35 {
36 return text.c_str();
37 }
38
39 private:
40
41 std::string text;
42 };
43
44 /// Helper macros to convert `__LINE__` into a string literal.
45 #define MAKESTRING2(x) #x
46 #define MAKESTRING(x) MAKESTRING2(x)
47
48 // Helper macro to use when throwing a `PException`.
49 #define MakePException(text) PException(std::string() + text + std::string(" at " __FILE__ ":" MAKESTRING(__LINE__)))
50