NAWA 0.9
Web Application Framework for C++
Exception.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2019-2022 Tobias Flaig.
3 *
4 * This file is part of nawa.
5 *
6 * nawa is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General Public License,
8 * version 3, as published by the Free Software Foundation.
9 *
10 * nawa is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public License
16 * along with nawa. If not, see <https://www.gnu.org/licenses/>.
17 */
18
24#ifndef NAWA_EXCEPTION_H
25#define NAWA_EXCEPTION_H
26
27#include <sstream>
28#include <string>
29
30namespace 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