NAWA  0.8
Web Application Framework for C++
Exception.h
Go to the documentation of this file.
1 
6 /*
7  * Copyright (C) 2019-2021 Tobias Flaig.
8  *
9  * This file is part of nawa.
10  *
11  * nawa is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License,
13  * version 3, as published by the Free Software Foundation.
14  *
15  * nawa is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU Lesser General Public License for more details.
19  *
20  * You should have received a copy of the GNU Lesser General Public License
21  * along with nawa. If not, see <https://www.gnu.org/licenses/>.
22  */
23 
24 #ifndef NAWA_EXCEPTION_H
25 #define NAWA_EXCEPTION_H
26 
27 #include <sstream>
28 #include <string>
29 
30 namespace nawa {
31 
35  class Exception : public std::exception {
36  int errorCode;
37  std::string message;
38  std::string debugMessage;
39  public:
47  Exception(const std::string& inFunction, int errorCode, const std::string& message = "No message provided.",
48  const std::string& additionalDebugInfo = std::string())
49  : errorCode(errorCode),
50  message(message) {
51  std::stringstream mstream;
52  mstream << "[NAWA Exception #" << errorCode << " in " << inFunction << "] " << message;
53  if (!additionalDebugInfo.empty()) {
54  mstream << " [Debug Info:] " << additionalDebugInfo;
55  }
56  debugMessage = mstream.str();
57  }
58 
63  [[nodiscard]] virtual int getErrorCode() const noexcept {
64  return errorCode;
65  }
66 
71  [[nodiscard]] virtual std::string getMessage() const noexcept {
72  return message;
73  }
74 
79  [[nodiscard]] virtual std::string getDebugMessage() const noexcept {
80  return debugMessage;
81  }
82 
88  char const* what() const noexcept override {
89  return debugMessage.c_str();
90  }
91  };
92 }// namespace nawa
93 
94 #endif//NAWA_EXCEPTION_H
char const * what() const noexcept override
Definition: Exception.h:88
virtual int getErrorCode() const noexcept
Definition: Exception.h:63
virtual std::string getMessage() const noexcept
Definition: Exception.h:71
virtual std::string getDebugMessage() const noexcept
Definition: Exception.h:79
Exception(const std::string &inFunction, int errorCode, const std::string &message="No message provided.", const std::string &additionalDebugInfo=std::string())
Definition: Exception.h:47
Definition: AppInit.h:31