LCOV - code coverage report
Current view: top level - src/utils/common - UtilExceptions.h (source / functions) Hit Total Coverage
Test: lcov.info Lines: 17 17 100.0 %
Date: 2024-05-02 15:31:40 Functions: 5 5 100.0 %

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

Generated by: LCOV version 1.14