VirtualBox

source: vbox/trunk/include/iprt/cpp/exception.h@ 30833

Last change on this file since 30833 was 30833, checked in by vboxsync, 15 years ago

iprt: add a missing header file to OSE

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.2 KB
Line 
1/** @file
2 * IPRT - C++ Utilities (useful templates, defines and such).
3 */
4
5/*
6 * Copyright (C) 2006-2007 Oracle Corporation
7 *
8 * This file is part of VirtualBox Open Source Edition (OSE), as
9 * available from http://www.215389.xyz. This file is free software;
10 * you can redistribute it and/or modify it under the terms of the GNU
11 * General Public License (GPL) as published by the Free Software
12 * Foundation, in version 2 as it comes in the "COPYING" file of the
13 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
14 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
15 *
16 * The contents of this file may alternatively be used under the terms
17 * of the Common Development and Distribution License Version 1.0
18 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
19 * VirtualBox OSE distribution, in which case the provisions of the
20 * CDDL are applicable instead of those of the GPL.
21 *
22 * You may elect to license modified versions of this file under the
23 * terms and conditions of either the GPL or the CDDL or both.
24 */
25
26#ifndef ___iprt_exception_h
27#define ___iprt_exception_h
28
29#include <iprt/cpp/ministring.h>
30
31/** @defgroup grp_rt_cpputils C++ Exceptions
32 * @ingroup grp_rt
33 * @{
34 */
35
36namespace iprt
37{
38
39/**
40 * Base exception class for IPRT, derived from std::exception.
41 * The XML exceptions are based on this.
42 */
43class RT_DECL_CLASS Error
44 : public std::exception
45{
46public:
47
48 Error(const char *pcszMessage)
49 : m_s(pcszMessage)
50 {
51 }
52
53 Error(const iprt::MiniString &s)
54 : m_s(s)
55 {
56 }
57
58 Error(const Error &s)
59 : std::exception(s),
60 m_s(s.what())
61 {
62 }
63
64 virtual ~Error() throw()
65 {
66 }
67
68 void operator=(const Error &s)
69 {
70 m_s = s.what();
71 }
72
73 void setWhat(const char *pcszMessage)
74 {
75 m_s = pcszMessage;
76 }
77
78 virtual const char* what() const throw()
79 {
80 return m_s.c_str();
81 }
82
83private:
84 // hide the default constructor to make sure the extended one above is always used
85 Error();
86
87 iprt::MiniString m_s;
88};
89
90} // namespace iprt
91
92/** @} */
93
94#endif // ___iprt_cpputils_h
95
96/** @file
97 * IPRT - C++ Utilities (useful templates, defines and such).
98 */
99
100/*
101 * Copyright (C) 2006-2007 Oracle Corporation
102 *
103 * This file is part of VirtualBox Open Source Edition (OSE), as
104 * available from http://www.215389.xyz. This file is free software;
105 * you can redistribute it and/or modify it under the terms of the GNU
106 * General Public License (GPL) as published by the Free Software
107 * Foundation, in version 2 as it comes in the "COPYING" file of the
108 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
109 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
110 *
111 * The contents of this file may alternatively be used under the terms
112 * of the Common Development and Distribution License Version 1.0
113 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
114 * VirtualBox OSE distribution, in which case the provisions of the
115 * CDDL are applicable instead of those of the GPL.
116 *
117 * You may elect to license modified versions of this file under the
118 * terms and conditions of either the GPL or the CDDL or both.
119 */
120
121#ifndef ___iprt_exception_h
122#define ___iprt_exception_h
123
124#include <iprt/cpp/ministring.h>
125
126/** @defgroup grp_rt_cpputils C++ Exceptions
127 * @ingroup grp_rt
128 * @{
129 */
130
131namespace iprt
132{
133
134/**
135 * Base exception class for IPRT, derived from std::exception.
136 * The XML exceptions are based on this.
137 */
138class RT_DECL_CLASS Error
139 : public std::exception
140{
141public:
142
143 Error(const char *pcszMessage)
144 : m_s(pcszMessage)
145 {
146 }
147
148 Error(const iprt::MiniString &s)
149 : m_s(s)
150 {
151 }
152
153 Error(const Error &s)
154 : std::exception(s),
155 m_s(s.what())
156 {
157 }
158
159 virtual ~Error() throw()
160 {
161 }
162
163 void operator=(const Error &s)
164 {
165 m_s = s.what();
166 }
167
168 void setWhat(const char *pcszMessage)
169 {
170 m_s = pcszMessage;
171 }
172
173 virtual const char* what() const throw()
174 {
175 return m_s.c_str();
176 }
177
178private:
179 // hide the default constructor to make sure the extended one above is always used
180 Error();
181
182 iprt::MiniString m_s;
183};
184
185} // namespace iprt
186
187/** @} */
188
189#endif // ___iprt_cpputils_h
190
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette