Line data Source code
1 : /****************************************************************************/
2 : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3 : // Copyright (C) 2001-2026 German Aerospace Center (DLR) and others.
4 : // This program and the accompanying materials are made available under the
5 : // terms of the Eclipse Public License 2.0 which is available at
6 : // https://www.eclipse.org/legal/epl-2.0/
7 : // This Source Code may also be made available under the following Secondary
8 : // Licenses when the conditions for such availability set forth in the Eclipse
9 : // Public License 2.0 are satisfied: GNU General Public License, version 2
10 : // or later which is available at
11 : // https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12 : // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13 : /****************************************************************************/
14 : /// @file UtilExceptions.cpp
15 : /// @author Daniel Krajzewicz
16 : /// @author Christian Roessel
17 : /// @author Michael Behrisch
18 : /// @author Felix Brack
19 : /// @date Mon, 17 Dec 2001
20 : ///
21 : // Exceptions for used by some utility classes
22 : /****************************************************************************/
23 : #include <config.h>
24 :
25 : // stacktrace is not supported in MAC
26 : #if defined(HAVE_BOOST) && !defined(__APPLE__)
27 : #ifdef _MSC_VER
28 : // needed to avoid problem in boost win winsocket
29 : #pragma warning(push, 0)
30 : #define WIN32_LEAN_AND_MEAN
31 : #define NOMINMAX
32 : #include <windows.h>
33 : #include <boost/stacktrace.hpp>
34 : #pragma warning(pop)
35 : #else
36 : #pragma GCC diagnostic push
37 : #pragma GCC diagnostic ignored "-Wall"
38 : #pragma GCC diagnostic ignored "-Wextra"
39 : #include <boost/stacktrace.hpp>
40 : #pragma GCC diagnostic pop
41 : #endif
42 : #endif
43 :
44 : #include "UtilExceptions.h"
45 : #include "Translation.h"
46 :
47 : // ===========================================================================
48 : // class definitions
49 : // ===========================================================================
50 :
51 : // ---------------------------------------------------------------------------
52 : // ProcessError - methods
53 : // ---------------------------------------------------------------------------
54 :
55 4514 : ProcessError::ProcessError() :
56 4514 : std::runtime_error(TL("Process Error")) {
57 : // process trace
58 4514 : processTrace();
59 4514 : }
60 :
61 :
62 3859530 : ProcessError::ProcessError(const std::string& msg) :
63 3859530 : std::runtime_error(msg) {
64 : // process trace
65 3859530 : processTrace();
66 3859530 : }
67 :
68 :
69 : const std::string&
70 0 : ProcessError::getTrace() const {
71 0 : return myTrace;
72 : }
73 :
74 :
75 : void
76 3864044 : ProcessError::processTrace() {
77 : // only process if we have boost and we're not in apple
78 : #if defined(HAVE_BOOST) && !defined(__APPLE__)
79 : // declare stacktrace
80 : boost::stacktrace::stacktrace st;
81 : // convert trace using ostringstream
82 : std::ostringstream oss;
83 : oss << st;
84 : myTrace = oss.str();
85 : #endif
86 3864044 : }
87 :
88 : // ---------------------------------------------------------------------------
89 : // ProcessError - methods
90 : // ---------------------------------------------------------------------------
91 :
92 3817500 : InvalidArgument::InvalidArgument(const std::string& message) :
93 3817500 : ProcessError(message) {
94 3817500 : }
95 :
96 : // ---------------------------------------------------------------------------
97 : // ProcessError - methods
98 : // ---------------------------------------------------------------------------
99 :
100 1850 : EmptyData::EmptyData() :
101 1850 : ProcessError(TL("Empty Data")) {
102 1850 : }
103 :
104 : // ---------------------------------------------------------------------------
105 : // ProcessError - methods
106 : // ---------------------------------------------------------------------------
107 :
108 23683 : FormatException::FormatException(const std::string& msg) :
109 23683 : ProcessError(msg) {
110 23683 : }
111 :
112 : // ---------------------------------------------------------------------------
113 : // ProcessError - methods
114 : // ---------------------------------------------------------------------------
115 :
116 23433 : NumberFormatException::NumberFormatException(const std::string& data) :
117 46866 : FormatException(TLF("Invalid Number Format %", data)) {
118 23433 : }
119 :
120 : // ---------------------------------------------------------------------------
121 : // ProcessError - methods
122 : // ---------------------------------------------------------------------------
123 :
124 8 : TimeFormatException::TimeFormatException(const std::string& data) :
125 16 : FormatException(TLF("Invalid Time Format %", data)) {
126 8 : }
127 :
128 : // ---------------------------------------------------------------------------
129 : // ProcessError - methods
130 : // ---------------------------------------------------------------------------
131 :
132 147 : BoolFormatException::BoolFormatException(const std::string& data) :
133 294 : FormatException(TLF("Invalid Bool Format %", data)) {
134 147 : }
135 :
136 : // ---------------------------------------------------------------------------
137 : // ProcessError - methods
138 : // ---------------------------------------------------------------------------
139 :
140 6 : OutOfBoundsException::OutOfBoundsException() :
141 6 : ProcessError(TL("Out Of Bounds")) {
142 6 : }
143 :
144 :
145 0 : OutOfBoundsException::OutOfBoundsException(const std::string& msg) :
146 0 : ProcessError(msg) {
147 0 : }
148 :
149 :
150 : // ---------------------------------------------------------------------------
151 : // ProcessError - methods
152 : // ---------------------------------------------------------------------------
153 :
154 0 : UnknownElement::UnknownElement() :
155 0 : ProcessError(TL("Unknown Element")) {
156 0 : }
157 :
158 :
159 976 : UnknownElement::UnknownElement(const std::string& msg) :
160 976 : ProcessError(msg) {
161 976 : }
162 :
163 : // ---------------------------------------------------------------------------
164 : // ProcessError - methods
165 : // ---------------------------------------------------------------------------
166 :
167 103 : IOError::IOError(const std::string& message) :
168 103 : ProcessError(message) {
169 103 : }
|