helics  2.8.1
helicsExceptions.hpp
1 /*
2 Copyright (c) 2017-2021,
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_
9 #define _HELICS_CPP98_EXCEPTIONS_
10 #pragma once
11 
12 #include "../shared_api_library/helics.h"
13 #include "config.hpp"
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 helics_error*() { return &eObj; }
53 
54  private:
55  helics_error eObj;
56 };
57 } // namespace helicscpp
58 
59 #endif /*_HELICS_CPP98_EXCEPTIONS_*/
helicscpp::HelicsException::errorCode
int errorCode() const
Definition: helicsExceptions.hpp:30
helicscpp::HelicsException
Definition: helicsExceptions.hpp:19
helicsErrorInitialize
helics_error helicsErrorInitialize(void)
Definition: helicsExport.cpp:47
helicscpp::hThrowOnError::~hThrowOnError
~hThrowOnError() HELICS_THROWS_EXCEPTION
Definition: helicsExceptions.hpp:45
helicscpp::HelicsException::HelicsException
HelicsException(int error_code, const char *errorString)
Definition: helicsExceptions.hpp:25
helicscpp::hThrowOnError
Definition: helicsExceptions.hpp:38
helics_error
Definition: api-data.h:166
helicscpp::hThrowOnError::hThrowOnError
hThrowOnError()
Definition: helicsExceptions.hpp:41
helics_error::error_code
int32_t error_code
Definition: api-data.h:167
helics_error::message
const char * message
Definition: api-data.h:168
helicscpp
Definition: cpp98/Broker.hpp:18