1 | /** @file
|
---|
2 | * IPRT - C++ Base Exceptions.
|
---|
3 | */
|
---|
4 |
|
---|
5 | /*
|
---|
6 | * Copyright (C) 2006-2022 Oracle and/or its affiliates.
|
---|
7 | *
|
---|
8 | * This file is part of VirtualBox base platform packages, as
|
---|
9 | * available from https://www.virtualbox.org.
|
---|
10 | *
|
---|
11 | * This program is free software; you can redistribute it and/or
|
---|
12 | * modify it under the terms of the GNU General Public License
|
---|
13 | * as published by the Free Software Foundation, in version 3 of the
|
---|
14 | * License.
|
---|
15 | *
|
---|
16 | * This program is distributed in the hope that it will be useful, but
|
---|
17 | * WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
19 | * General Public License for more details.
|
---|
20 | *
|
---|
21 | * You should have received a copy of the GNU General Public License
|
---|
22 | * along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
23 | *
|
---|
24 | * The contents of this file may alternatively be used under the terms
|
---|
25 | * of the Common Development and Distribution License Version 1.0
|
---|
26 | * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
|
---|
27 | * in the VirtualBox distribution, in which case the provisions of the
|
---|
28 | * CDDL are applicable instead of those of the GPL.
|
---|
29 | *
|
---|
30 | * You may elect to license modified versions of this file under the
|
---|
31 | * terms and conditions of either the GPL or the CDDL or both.
|
---|
32 | *
|
---|
33 | * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
|
---|
34 | */
|
---|
35 |
|
---|
36 | #ifndef IPRT_INCLUDED_cpp_exception_h
|
---|
37 | #define IPRT_INCLUDED_cpp_exception_h
|
---|
38 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
39 | # pragma once
|
---|
40 | #endif
|
---|
41 |
|
---|
42 | #include <iprt/cpp/ministring.h>
|
---|
43 | #include <exception>
|
---|
44 |
|
---|
45 | #if RT_MSC_PREREQ(RT_MSC_VER_VC140)
|
---|
46 | # pragma warning(push)
|
---|
47 | # pragma warning(disable:4275) /* non dll-interface class 'std::exception' used as base for dll-interface class 'RTCError' */
|
---|
48 | #endif
|
---|
49 |
|
---|
50 |
|
---|
51 | /** @defgroup grp_rt_cpp_exceptions C++ Exceptions
|
---|
52 | * @ingroup grp_rt_cpp
|
---|
53 | * @{
|
---|
54 | */
|
---|
55 |
|
---|
56 | /**
|
---|
57 | * Base exception class for IPRT, derived from std::exception.
|
---|
58 | * The XML exceptions are based on this.
|
---|
59 | */
|
---|
60 | class RT_DECL_CLASS RTCError
|
---|
61 | : public std::exception
|
---|
62 | {
|
---|
63 | public:
|
---|
64 |
|
---|
65 | RTCError(const char *pszMessage)
|
---|
66 | : m_strMsg(pszMessage)
|
---|
67 | {
|
---|
68 | }
|
---|
69 |
|
---|
70 | RTCError(const RTCString &a_rstrMessage)
|
---|
71 | : m_strMsg(a_rstrMessage)
|
---|
72 | {
|
---|
73 | }
|
---|
74 |
|
---|
75 | RTCError(const RTCError &a_rSrc)
|
---|
76 | : std::exception(a_rSrc),
|
---|
77 | m_strMsg(a_rSrc.what())
|
---|
78 | {
|
---|
79 | }
|
---|
80 |
|
---|
81 | virtual ~RTCError() throw()
|
---|
82 | {
|
---|
83 | }
|
---|
84 |
|
---|
85 | void operator=(const RTCError &a_rSrc)
|
---|
86 | {
|
---|
87 | m_strMsg = a_rSrc.what();
|
---|
88 | }
|
---|
89 |
|
---|
90 | void setWhat(const char *a_pszMessage)
|
---|
91 | {
|
---|
92 | m_strMsg = a_pszMessage;
|
---|
93 | }
|
---|
94 |
|
---|
95 | virtual const char *what() const throw()
|
---|
96 | {
|
---|
97 | return m_strMsg.c_str();
|
---|
98 | }
|
---|
99 |
|
---|
100 | private:
|
---|
101 | /**
|
---|
102 | * Hidden default constructor making sure that the extended one above is
|
---|
103 | * always used.
|
---|
104 | */
|
---|
105 | RTCError();
|
---|
106 |
|
---|
107 | protected:
|
---|
108 | /** The exception message. */
|
---|
109 | RTCString m_strMsg;
|
---|
110 | };
|
---|
111 |
|
---|
112 | /** @} */
|
---|
113 |
|
---|
114 | #if RT_MSC_PREREQ(RT_MSC_VER_VC140)
|
---|
115 | # pragma warning(pop)
|
---|
116 | #endif
|
---|
117 | #endif /* !IPRT_INCLUDED_cpp_exception_h */
|
---|
118 |
|
---|