| helics 3.6.1

helicsExceptions.hpp
1 /*
2 Copyright (c) 2017-2025,
3 Battelle Memorial Institute; Lawrence Livermore National Security, LLC; Alliance for Sustainable
4 Energy, LLC. See the top-level NOTICE for additional details. All rights reserved.
5 SPDX-License-Identifier: BSD-3-Clause
6 */
7
8 #ifndef HELICS_CPP98_EXCEPTIONS_HPP_
9 #define HELICS_CPP98_EXCEPTIONS_HPP_
10 #pragma once
11
12 #include "config.hpp"
13 #include "helics/helics.h"
14
15 #include <stdexcept>
16
17 namespace helicscpp {
19 class HelicsException: public std::runtime_error {
20 public:
25 explicit HelicsException(int error_code, const char* errorString):
26 std::runtime_error(errorString), eCode(error_code)
27 {
28 }
30 int errorCode() const { return eCode; }
31
32 private:
33 int eCode;
34 };
35
38 class hThrowOnError {
39 public:
41 hThrowOnError(): eObj(helicsErrorInitialize()) {}
45 ~hThrowOnError() HELICS_THROWS_EXCEPTION
46 {
47 if (eObj.error_code != 0) {
48 throw HelicsException(eObj.error_code, eObj.message);
49 }
50 }
52 operator HelicsError*() { return &eObj; }
53
54 private:
55 HelicsError eObj;
56 };
57 } // namespace helicscpp
58
59 #endif /*HELICS_CPP98_EXCEPTIONS_HPP_*/
helicscpp::HelicsException
Definition: helicsExceptions.hpp:19
helicscpp::HelicsException::errorCode
int errorCode() const
Definition: helicsExceptions.hpp:30
helicscpp::HelicsException::HelicsException
HelicsException(int error_code, const char *errorString)
Definition: helicsExceptions.hpp:25
helicscpp::hThrowOnError
Definition: helicsExceptions.hpp:38
helicscpp::hThrowOnError::hThrowOnError
hThrowOnError()
Definition: helicsExceptions.hpp:41
helicscpp::hThrowOnError::~hThrowOnError
~hThrowOnError() HELICS_THROWS_EXCEPTION
Definition: helicsExceptions.hpp:45
helicsErrorInitialize
HelicsError helicsErrorInitialize(void)
Definition: helicsExport.cpp:60
helicscpp
Definition: cpp98/Broker.hpp:18
HelicsError
Definition: api-data.h:177
HelicsError::message
const char * message
Definition: api-data.h:179
HelicsError::error_code
int32_t error_code
Definition: api-data.h:178