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.h
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 : #pragma once
24 : #include <config.h>
25 :
26 : #include <cassert>
27 : #include <string>
28 : #include <stdexcept>
29 :
30 : // ===========================================================================
31 : // class definitions
32 : // ===========================================================================
33 : /**
34 : * ProcessError
35 : * The base class for all exceptions in SUMO. The reason itself can either be
36 : * reported before throwing the exception or in the message parameter.
37 : */
38 48 : class ProcessError : public std::runtime_error {
39 :
40 : public:
41 : /// @brief constructor
42 : ProcessError();
43 :
44 : /// @brief parameter constructor
45 : ProcessError(const std::string& msg);
46 :
47 : /// @brief get trace
48 : const std::string& getTrace() const;
49 :
50 : private:
51 : /// @brief exception trace
52 : std::string myTrace;
53 :
54 : /// @brief process trace
55 : void processTrace();
56 : };
57 :
58 :
59 : /**
60 : * InvalidArgument
61 : * Thrown when an argument was not proper in the current context.
62 : * A message will be supplied.
63 : */
64 : class InvalidArgument : public ProcessError {
65 :
66 : public:
67 : /// @brief constructor
68 : InvalidArgument(const std::string& message);
69 : };
70 :
71 :
72 : /**
73 : * EmptyData
74 : * Thrown when data required by a method is missing
75 : */
76 : class EmptyData : public ProcessError {
77 :
78 : public:
79 : /// @brief constructor
80 : EmptyData();
81 : };
82 :
83 :
84 : /**
85 : * FormatException
86 : * Thrown when a string that shall be converted into
87 : * something else contained the wrong characters
88 : */
89 : class FormatException : public ProcessError {
90 :
91 : public:
92 : /// @brief constructor
93 : FormatException(const std::string& msg);
94 : };
95 :
96 :
97 : /**
98 : * NumberFormatException
99 : * Thrown when the string that shall be converted into a
100 : * numerical representation has any other characters then
101 : * digits and a dot
102 : */
103 : class NumberFormatException : public FormatException {
104 :
105 : public:
106 : /// @brief constructor
107 : NumberFormatException(const std::string& data);
108 : };
109 :
110 :
111 : /**
112 : * TimeFormatException
113 : * Thrown when the string that shall be converted into a
114 : * time representation HH:MM:SS isn't valid
115 : */
116 : class TimeFormatException : public FormatException {
117 :
118 : public:
119 : /// @brief constructor
120 : TimeFormatException(const std::string& data);
121 : };
122 :
123 :
124 : /**
125 : * BoolFormatException
126 : * Thrown when the string that shall be converted into a
127 : * boolean does not match
128 : */
129 : class BoolFormatException : public FormatException {
130 :
131 : public:
132 : /// @brief constructor
133 : BoolFormatException(const std::string& data);
134 : };
135 :
136 :
137 : /**
138 : * OutOfBoundsException
139 : * Thrown when an array element out of the array's
140 : * bounderies is accessed
141 : */
142 : class OutOfBoundsException : public ProcessError {
143 :
144 : public:
145 : /// @brief constructor (default message: "Out Of Bounds")
146 : OutOfBoundsException();
147 :
148 : /// @brief constructor
149 : OutOfBoundsException(const std::string& msg);
150 : };
151 :
152 :
153 : /**
154 : * UnknownElement
155 : * Thrown when a named element is tried to be accessed
156 : * which is not known to the container
157 : */
158 : class UnknownElement : public ProcessError {
159 :
160 : public:
161 : /// @brief constructor
162 : UnknownElement();
163 :
164 : /// @brief constructor
165 : UnknownElement(const std::string& msg);
166 : };
167 :
168 : /**
169 : * IOError
170 : */
171 : class IOError : public ProcessError {
172 :
173 : public:
174 : /// @brief constructor
175 : IOError(const std::string& message);
176 : };
177 :
178 : /// define SOFT_ASSERT raise an assertion in debug mode everywhere except on the windows test server
179 : #ifdef MSVC_TEST_SERVER
180 : #ifdef _DEBUG
181 : #define SOFT_ASSERT(expr) if (!(expr)) {throw ProcessError("should not happen");}
182 : #else
183 : #define SOFT_ASSERT(expr)
184 : #endif
185 : #else
186 : #define SOFT_ASSERT(expr) assert(expr);
187 : #endif
|