/****************************************************************************/1// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo2// Copyright (C) 2001-2025 German Aerospace Center (DLR) and others.3// This program and the accompanying materials are made available under the4// terms of the Eclipse Public License 2.0 which is available at5// https://www.eclipse.org/legal/epl-2.0/6// This Source Code may also be made available under the following Secondary7// Licenses when the conditions for such availability set forth in the Eclipse8// Public License 2.0 are satisfied: GNU General Public License, version 29// or later which is available at10// https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html11// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later12/****************************************************************************/13/// @file UtilExceptions.h14/// @author Daniel Krajzewicz15/// @author Christian Roessel16/// @author Michael Behrisch17/// @author Felix Brack18/// @date Mon, 17 Dec 200119///20// Exceptions for used by some utility classes21/****************************************************************************/22#pragma once23#include <config.h>24#include <string>25#include <stdexcept>2627#include "Translation.h"282930// ===========================================================================31// class definitions32// ===========================================================================33/**34* ProcessError35* The base class for all exceptions in SUMO. The reason itself can either be36* reported before throwing the exception or in the message parameter.37*/38class ProcessError : public std::runtime_error {39public:40/// @brief constructor41ProcessError()42: std::runtime_error(TL("Process Error")) {}4344/// @brief constructor45ProcessError(const std::string& msg)46: std::runtime_error(msg) {}47};484950/**51* InvalidArgument52* Thrown when an argument was not proper in the current context.53* A message will be supplied.54*/55class InvalidArgument : public ProcessError {56public:57/// @brief constructor58InvalidArgument(const std::string& message)59: ProcessError(message) {}60};616263/**64* EmptyData65* Thrown when data required by a method is missing66*/67class EmptyData : public ProcessError {68public:69/// @brief constructor70EmptyData()71: ProcessError(TL("Empty Data")) {}72};737475/**76* FormatException77* Thrown when a string that shall be converted into78* something else contained the wrong characters79*/80class FormatException : public ProcessError {81public:82/// @brief constructor83FormatException(const std::string& msg)84: ProcessError(msg) {}85};868788/**89* NumberFormatException90* Thrown when the string that shall be converted into a91* numerical representation has any other characters then92* digits and a dot93*/94class NumberFormatException : public FormatException {95public:96/// @brief constructor97NumberFormatException(const std::string& data)98: FormatException(TLF("Invalid Number Format %", data)) {}99};100101102/**103* TimeFormatException104* Thrown when the string that shall be converted into a105* time representation HH:MM:SS isn't valid106*/107class TimeFormatException : public FormatException {108public:109/// @brief constructor110TimeFormatException(const std::string& data)111: FormatException(TLF("Invalid Time Format %", data)) {}112};113114115/**116* BoolFormatException117* Thrown when the string that shall be converted into a118* boolean does not match119*/120class BoolFormatException : public FormatException {121public:122/// @brief constructor123BoolFormatException(const std::string& data)124: FormatException(TLF("Invalid Bool Format %", data)) {}125};126127128/**129* OutOfBoundsException130* Thrown when an array element out of the array's131* bounderies is accessed132*/133class OutOfBoundsException : public ProcessError {134public:135/// @brief constructor136OutOfBoundsException(const std::string& msg = TL("Out Of Bounds"))137: ProcessError(msg) {}138};139140141/**142* UnknownElement143* Thrown when a named element is tried to be accessed144* which is not known to the container145*/146class UnknownElement : public ProcessError {147public:148/// @brief constructor149UnknownElement()150: ProcessError(TL("Unknown Element")) {}151152/// @brief constructor153UnknownElement(const std::string& msg)154: ProcessError(msg) {}155};156157/**158* IOError159*/160class IOError : public ProcessError {161public:162/// @brief constructor163IOError(const std::string& message)164: ProcessError(message) {}165};166167/// define SOFT_ASSERT raise an assertion in debug mode everywhere except on the windows test server168#ifdef MSVC_TEST_SERVER169#ifdef _DEBUG170#define SOFT_ASSERT(expr) if (!(expr)) {throw ProcessError(TL("should not happen"));}171#else172#define SOFT_ASSERT(expr)173#endif174#else175#define SOFT_ASSERT(expr) assert(expr);176#endif177178179