MeLOn
exceptions.h
Go to the documentation of this file.
1 /**********************************************************************************
2  * Copyright (c) 2020 Process Systems Engineering (AVT.SVT), RWTH Aachen University
3  *
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  * http://www.eclipse.org/legal/epl-2.0.
7  *
8  * SPDX-License-Identifier: EPL-2.0
9  *
10  * @file exceptions.h
11  *
12  * @brief File declaring the MeLOn exception class.
13  *
14  **********************************************************************************/
15 
16 #pragma once
17 
18 #include <exception>
19 #include <sstream>
20 #include <string>
21 #include <typeinfo>
22 
32 class MelonException : public std::exception {
33 private:
34  std::string _msg{ "" }; ;
36 public:
42  explicit MelonException(const std::string& arg) :
43  MelonException(arg, nullptr)
44  {
45  }
46 
53  MelonException(const std::string& arg, const std::exception& e) :
54  MelonException(arg, &e)
55  {
56  }
57 
64  MelonException(const std::string& arg, const std::exception* e)
65  {
66  std::ostringstream message;
67  if (e) {
68  if (typeid(*e).name() != typeid(*this).name()) {
69  message << " Original std::exception: " << typeid(*e).name() << ": " << std::endl
70  << " ";
71  }
72  message << e->what() << std::endl;
73  }
74  message << arg;
75  _msg = message.str();
76  }
77 
83  const char* what() const noexcept
84  {
85  return _msg.c_str();
86  }
87 
88 };
MelonException::MelonException
MelonException()
MelonException::MelonException
MelonException(const std::string &arg)
Constructor used for forwarding.
Definition: exceptions.h:42
MelonException::MelonException
MelonException(const std::string &arg, const std::exception *e)
Constructor used printing a FeedForwardNet Exception.
Definition: exceptions.h:64
MelonException::MelonException
MelonException(const std::string &arg, const std::exception &e)
Constructor used for forwarding.
Definition: exceptions.h:53
MelonException::_msg
std::string _msg
Definition: exceptions.h:34
MelonException
This class defines the exceptions thrown by FeedForwardNet.
Definition: exceptions.h:32
MelonException::what
const char * what() const noexcept
Function to return the error message.
Definition: exceptions.h:83