OMCompiler/SimulationRuntime/cpp/Core/Utils/Modelica/ModelicaSimulationError.h
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /* | ||
| 2 | * This file belongs to the OpenModelica Run-Time System | ||
| 3 | * | ||
| 4 | * Copyright (c) 1998-2026, Open Source Modelica Consortium (OSMC), c/o Linköpings | ||
| 5 | * universitet, Department of Computer and Information Science, SE-58183 Linköping, Sweden. All rights | ||
| 6 | * reserved. | ||
| 7 | * | ||
| 8 | * THIS PROGRAM IS PROVIDED UNDER THE TERMS OF THE BSD NEW LICENSE OR THE | ||
| 9 | * AGPL VERSION 3 LICENSE OR THE OSMC PUBLIC LICENSE (OSMC-PL) VERSION 1.8. ANY | ||
| 10 | * USE, REPRODUCTION OR DISTRIBUTION OF THIS PROGRAM CONSTITUTES RECIPIENT'S | ||
| 11 | * ACCEPTANCE OF THE BSD NEW LICENSE OR THE OSMC PUBLIC LICENSE OR THE AGPL | ||
| 12 | * VERSION 3, ACCORDING TO RECIPIENTS CHOICE. | ||
| 13 | * | ||
| 14 | * The OpenModelica software and the OSMC (Open Source Modelica Consortium) Public License | ||
| 15 | * (OSMC-PL) are obtained from OSMC, either from the above address, from the URLs: | ||
| 16 | * http://www.openmodelica.org or https://github.com/OpenModelica/ or | ||
| 17 | * http://www.ida.liu.se/projects/OpenModelica, and in the OpenModelica distribution. GNU | ||
| 18 | * AGPL version 3 is obtained from: https://www.gnu.org/licenses/licenses.html#GPL. The BSD NEW | ||
| 19 | * License is obtained from: http://www.opensource.org/licenses/BSD-3-Clause. | ||
| 20 | * | ||
| 21 | * This program is distributed WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 22 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, EXCEPT AS EXPRESSLY | ||
| 23 | * SET FORTH IN THE BY RECIPIENT SELECTED SUBSIDIARY LICENSE CONDITIONS OF | ||
| 24 | * OSMC-PL. | ||
| 25 | * | ||
| 26 | */ | ||
| 27 | |||
| 28 | #pragma once | ||
| 29 | /** @addtogroup coreUtils | ||
| 30 | * | ||
| 31 | * @{ | ||
| 32 | */ | ||
| 33 | |||
| 34 | |||
| 35 | //Enum for error types that can occur | ||
| 36 | enum SIMULATION_ERROR { | ||
| 37 | SOLVER, //all errors occur in solver (Euler,CVode) | ||
| 38 | ALGLOOP_SOLVER, //all errors occur in non-,lin-solver (Kinsol,Newton,Hybrj) | ||
| 39 | MODEL_EQ_SYSTEM, //all errors occur in model system class during simulation | ||
| 40 | ALGLOOP_EQ_SYSTEM,//all errors occur in algloop system class during simulation | ||
| 41 | MODEL_FACTORY, //all errors occur model system factory classes | ||
| 42 | SIMMANAGER,//all errors occur in simulation manager | ||
| 43 | EVENT_HANDLING,//all errors occur during event handling | ||
| 44 | TIME_EVENTS, //all errors occur during handling time events | ||
| 45 | DATASTORAGE , //all errors occur during write data (TextfileWriter,MatfileWriter,BufferReaderWriter | ||
| 46 | UTILITY,//all errors occur in utility functions | ||
| 47 | MODEL_ARRAY_FUNCTION,//all errors occur in array functions | ||
| 48 | MATH_FUNCTION //all errors occur in math functions | ||
| 49 | }; | ||
| 50 | |||
| 51 | /* | ||
| 52 | Exception class for all simulation errors | ||
| 53 | */ | ||
| 54 | class ModelicaSimulationError : public runtime_error | ||
| 55 | { | ||
| 56 | public: | ||
| 57 | /** | ||
| 58 | * Create a new modelica error object with the given arguments. | ||
| 59 | * @param error_id The identifier related to the sender of the error. \see SIMULATION_ERROR for detail. | ||
| 60 | * @param error_info Error message that should be shown. | ||
| 61 | * @param description More detailed description of the occurred error e.g. the error-message of the inner exception | ||
| 62 | * @param suppress Set to true if the error should not appear on std::err and std::out. | ||
| 63 | */ | ||
| 64 | ✗ | ModelicaSimulationError(SIMULATION_ERROR error_id, const string& error_info, string description = "", bool suppress = false) | |
| 65 | ✗ | : runtime_error(error_info + (description.size() > 0 ? "\n" + description : "")) | |
| 66 | ✗ | , _error_id(error_id) | |
| 67 | ✗ | , _suppress(suppress) | |
| 68 | { | ||
| 69 | ✗ | } | |
| 70 | |||
| 71 | SIMULATION_ERROR getErrorID() | ||
| 72 | { | ||
| 73 | ✗ | return _error_id; | |
| 74 | } | ||
| 75 | |||
| 76 | bool isSuppressed() | ||
| 77 | { | ||
| 78 | ✗ | return _suppress; | |
| 79 | } | ||
| 80 | |||
| 81 | private: | ||
| 82 | SIMULATION_ERROR _error_id; | ||
| 83 | bool _suppress; | ||
| 84 | }; | ||
| 85 | |||
| 86 | //Helper functions to convert the error id to a readable format | ||
| 87 | #if defined (__vxworks) || defined (__TRICORE__) | ||
| 88 | /* adrpo: undefine BOOST_EXTENSION_EXPORT_DECL for these targets */ | ||
| 89 | #define BOOST_EXTENSION_EXPORT_DECL | ||
| 90 | #endif | ||
| 91 | //Helper functions to convert the error id to a readable format | ||
| 92 | BOOST_EXTENSION_EXPORT_DECL string error_id_string(SIMULATION_ERROR id); | ||
| 93 | //Helper functions to extend an error information for new additional string and time stamp | ||
| 94 | BOOST_EXTENSION_EXPORT_DECL string add_error_info(string new_info,string info,SIMULATION_ERROR id,double& time); | ||
| 95 | //Helper functions to extend an error information for new additional string | ||
| 96 | BOOST_EXTENSION_EXPORT_DECL string add_error_info(string new_info,string info,SIMULATION_ERROR id); | ||
| 97 | /** @} */ // end of coreUtils | ||
| 98 |