1 | /* -*- c++ -*- |
---|
2 | * |
---|
3 | * SOCLIB_LGPL_HEADER_BEGIN |
---|
4 | * |
---|
5 | * This file is part of SoCLib, GNU LGPLv2.1. |
---|
6 | * |
---|
7 | * SoCLib is free software; you can redistribute it and/or modify it |
---|
8 | * under the terms of the GNU Lesser General Public License as published |
---|
9 | * by the Free Software Foundation; version 2.1 of the License. |
---|
10 | * |
---|
11 | * SoCLib is distributed in the hope that it will be useful, but |
---|
12 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
14 | * Lesser General Public License for more details. |
---|
15 | * |
---|
16 | * You should have received a copy of the GNU Lesser General Public |
---|
17 | * License along with SoCLib; if not, write to the Free Software |
---|
18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
---|
19 | * 02110-1301 USA |
---|
20 | * |
---|
21 | * SOCLIB_LGPL_HEADER_END |
---|
22 | * |
---|
23 | * Copyright (c) UPMC, Lip6, Asim |
---|
24 | * Nicolas Pouillon <nipo@ssji.net>, 2007 |
---|
25 | * |
---|
26 | * Maintainers: nipo |
---|
27 | */ |
---|
28 | |
---|
29 | #ifndef SOCLIB_EXCEPTION_H_ |
---|
30 | #define SOCLIB_EXCEPTION_H_ |
---|
31 | |
---|
32 | #include <exception> |
---|
33 | #include <string> |
---|
34 | #include <iostream> |
---|
35 | |
---|
36 | namespace soclib { namespace exception { |
---|
37 | |
---|
38 | class Exception |
---|
39 | : public std::exception |
---|
40 | { |
---|
41 | std::string m_type; |
---|
42 | std::string m_message; |
---|
43 | |
---|
44 | public: |
---|
45 | Exception( const std::string &type, |
---|
46 | const std::string &message ) |
---|
47 | : m_type(type), m_message(message) |
---|
48 | {} |
---|
49 | |
---|
50 | virtual ~Exception() throw() |
---|
51 | { |
---|
52 | } |
---|
53 | |
---|
54 | virtual const char * what() const throw() |
---|
55 | { |
---|
56 | return m_message.c_str(); |
---|
57 | } |
---|
58 | |
---|
59 | void print( std::ostream &o ) const |
---|
60 | { |
---|
61 | o << "<soclib::exception::" << m_type << ": " << m_message << ">"; |
---|
62 | } |
---|
63 | |
---|
64 | friend std::ostream &operator << (std::ostream &o, const Exception &e) |
---|
65 | { |
---|
66 | e.print(o); |
---|
67 | return o; |
---|
68 | } |
---|
69 | }; |
---|
70 | |
---|
71 | class ValueError |
---|
72 | : public Exception |
---|
73 | { |
---|
74 | public: |
---|
75 | ValueError( const std::string &message ) |
---|
76 | : Exception( "ValueError", message ) |
---|
77 | {} |
---|
78 | }; |
---|
79 | |
---|
80 | class Collision |
---|
81 | : public Exception |
---|
82 | { |
---|
83 | public: |
---|
84 | Collision( const std::string &message ) |
---|
85 | : Exception( "Collision", message ) |
---|
86 | {} |
---|
87 | }; |
---|
88 | |
---|
89 | class RunTimeError |
---|
90 | : public Exception |
---|
91 | { |
---|
92 | public: |
---|
93 | RunTimeError( const std::string &message ) |
---|
94 | : Exception( "RunTimeError", message ) |
---|
95 | {} |
---|
96 | }; |
---|
97 | |
---|
98 | }} |
---|
99 | |
---|
100 | #endif /* SOCLIB_EXCEPTION_H_ */ |
---|
101 | |
---|
102 | // Local Variables: |
---|
103 | // tab-width: 4 |
---|
104 | // c-basic-offset: 4 |
---|
105 | // c-file-offsets:((innamespace . 0)(inline-open . 0)) |
---|
106 | // indent-tabs-mode: nil |
---|
107 | // End: |
---|
108 | |
---|
109 | // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 |
---|
110 | |
---|