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