Sese Framework  x.y.z
A cross-platform framework
载入中...
搜索中...
未找到
Exception.h
浏览该文件的文档.
1// Copyright 2024 libsese
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
22#pragma once
23
24#include <sese/Config.h>
26#include <sese/record/Logger.h>
28
29#include <exception>
30#include <utility>
31
32#ifdef SESE_PLATFORM_WINDOWS
33#pragma warning(disable : 4275)
34#endif
35
36namespace sese {
37
38#if defined(_MSC_VER)
39using NativeException = std::exception;
40#else
42class UnixException : public std::exception {
43public:
44 explicit UnixException(const char *message) : std::exception(), msg(message) {
45 }
46
47 [[nodiscard]] const char *what() const noexcept override {
48 return msg;
49 }
50
51private:
52 const char *msg{};
53};
54
56#endif
57
59class Exception : public NativeException {
60public:
61 explicit Exception(std::string message);
62
63 ~Exception() override;
64
66 void printStacktrace();
67
71
75
76 static uint16_t offset;
77
80 [[nodiscard]] const char *what() const noexcept override;
81
84 [[nodiscard]] std::string message() const noexcept;
85
86protected:
87 virtual std::string buildStacktrace();
88
89 std::string *message_;
90 system::StackInfo* stackInfo{};
91};
92} // namespace sese