helics  3.5.2
helicsExceptions.hpp
1 /*
2 Copyright (c) 2017-2024,
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 
39  public:
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_*/
Definition: helicsExceptions.hpp:19
int errorCode() const
Definition: helicsExceptions.hpp:30
HelicsException(int error_code, const char *errorString)
Definition: helicsExceptions.hpp:25
Definition: helicsExceptions.hpp:38
hThrowOnError()
Definition: helicsExceptions.hpp:41
~hThrowOnError() HELICS_THROWS_EXCEPTION
Definition: helicsExceptions.hpp:45
HelicsError helicsErrorInitialize(void)
Definition: helicsExport.cpp:57
Definition: cpp98/Broker.hpp:18
Definition: api-data.h:171
const char * message
Definition: api-data.h:173
int32_t error_code
Definition: api-data.h:172