1 /****************************************************************************/ 2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo 3 // Copyright (C) 2001-2019 German Aerospace Center (DLR) and others. 4 // This program and the accompanying materials 5 // are made available under the terms of the Eclipse Public License v2.0 6 // which accompanies this distribution, and is available at 7 // http://www.eclipse.org/legal/epl-v20.html 8 // SPDX-License-Identifier: EPL-2.0 9 /****************************************************************************/ 10 /// @file UtilExceptions.h 11 /// @author Daniel Krajzewicz 12 /// @author Christian Roessel 13 /// @author Michael Behrisch 14 /// @author Felix Brack 15 /// @date Mon, 17 Dec 2001 16 /// @version $Id$ 17 /// 18 // Exceptions for used by some utility classes 19 /****************************************************************************/ 20 #ifndef UtilExceptions_h 21 #define UtilExceptions_h 22 23 24 // =========================================================================== 25 // included modules 26 // =========================================================================== 27 28 #include <string> 29 #include <stdexcept> 30 31 32 // =========================================================================== 33 // class definitions 34 // =========================================================================== 35 /** 36 * ProcessError 37 * The base class for all exceptions in SUMO. The reason itself can either be 38 * reported before throwing the exception or in the message parameter. 39 */ 40 class ProcessError : public std::runtime_error { 41 public: 42 /// @brief constructor ProcessError()43 ProcessError() 44 : std::runtime_error("Process Error") {} 45 46 /// @brief constructor ProcessError(const std::string & msg)47 ProcessError(const std::string& msg) 48 : std::runtime_error(msg) {} 49 }; 50 51 52 /** 53 * InvalidArgument 54 * Thrown when an argument was not proper in the current context. 55 * A message will be supplied. 56 */ 57 class InvalidArgument : public ProcessError { 58 public: 59 /// @brief constructor InvalidArgument(const std::string & message)60 InvalidArgument(const std::string& message) 61 : ProcessError(message) {} 62 }; 63 64 65 /** 66 * EmptyData 67 * Thrown when data required by a method is missing 68 */ 69 class EmptyData : public ProcessError { 70 public: 71 /// @brief constructor EmptyData()72 EmptyData() 73 : ProcessError("Empty Data") {} 74 }; 75 76 77 /** 78 * FormatException 79 * Thrown when a string that shall be converted into 80 * something else contained the wrong characters 81 */ 82 class FormatException : public ProcessError { 83 public: 84 /// @brief constructor FormatException(const std::string & msg)85 FormatException(const std::string& msg) 86 : ProcessError(msg) {} 87 }; 88 89 90 /** 91 * NumberFormatException 92 * Thrown when the string that shall be converted into a 93 * numerical representation has any other characters then 94 * digits and a dot 95 */ 96 class NumberFormatException : public FormatException { 97 public: 98 /// @brief constructor NumberFormatException(const std::string & data)99 NumberFormatException(const std::string& data) 100 : FormatException("Invalid Number Format '" + data + "'") {} 101 }; 102 103 104 /** 105 * BoolFormatException 106 * Thrown when the string that shall be converted into a 107 * boolean does not match 108 */ 109 class BoolFormatException : public FormatException { 110 public: 111 /// @brief constructor BoolFormatException(const std::string & data)112 BoolFormatException(const std::string& data) 113 : FormatException("Invalid Bool Format '" + data + "'") {} 114 }; 115 116 117 /** 118 * OutOfBoundsException 119 * Thrown when an array element out of the array's 120 * bounderies is accessed 121 */ 122 class OutOfBoundsException : public ProcessError { 123 public: 124 /// @brief constructor OutOfBoundsException()125 OutOfBoundsException() 126 : ProcessError("Out Of Bounds") {} 127 }; 128 129 130 /** 131 * UnknownElement 132 * Thrown when a named element is tried to be accessed 133 * which is not known to the container 134 */ 135 class UnknownElement : public ProcessError { 136 public: 137 /// @brief constructor UnknownElement()138 UnknownElement() 139 : ProcessError("Unknown Element") {} 140 141 /// @brief constructor UnknownElement(const std::string & msg)142 UnknownElement(const std::string& msg) 143 : ProcessError(msg) {} 144 }; 145 146 147 class IOError : public ProcessError { 148 public: 149 /// @brief constructor IOError(const std::string & message)150 IOError(const std::string& message) 151 : ProcessError(message) {} 152 }; 153 154 /// define SOFT_ASSERT raise an assertion in debug mode everywhere except on the windows test server 155 #ifdef MSVC_TEST_SERVER 156 #ifdef _DEBUG 157 #define SOFT_ASSERT(expr) if (!(expr)) {throw ProcessError("should not happen");} 158 #else 159 #define SOFT_ASSERT(expr) 160 #endif 161 #else 162 #define SOFT_ASSERT(expr) assert(expr); 163 #endif 164 165 #endif 166 167 /****************************************************************************/ 168