TrinityCore
Loading...
Searching...
No Matches
Errors.h
Go to the documentation of this file.
1/*
2 * This file is part of the TrinityCore Project. See AUTHORS file for Copyright information
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the
6 * Free Software Foundation; either version 2 of the License, or (at your
7 * option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#ifndef TRINITYCORE_ERRORS_H
19#define TRINITYCORE_ERRORS_H
20
21#include "Define.h"
22#include <string>
23
24TC_COMMON_API std::string GetDebugInfo();
25
26namespace Trinity
27{
28 [[noreturn]] TC_COMMON_API void Assert(char const* file, int line, char const* function, char const* message, std::string debugInfo) noexcept;
29 [[noreturn]] TC_COMMON_API void Assert(char const* file, int line, char const* function, char const* message, std::string debugInfo, char const* format, ...) noexcept ATTR_PRINTF(6, 7);
30
31 [[noreturn]] TC_COMMON_API void Fatal(char const* file, int line, char const* function, char const* message, ...) noexcept ATTR_PRINTF(4, 5);
32
33 [[noreturn]] TC_COMMON_API void Error(char const* file, int line, char const* function, char const* message) noexcept;
34
35 [[noreturn]] TC_COMMON_API void Abort(char const* file, int line, char const* function) noexcept;
36 [[noreturn]] TC_COMMON_API void Abort(char const* file, int line, char const* function, char const* message, ...) noexcept;
37
38 TC_COMMON_API void Warning(char const* file, int line, char const* function, char const* message) noexcept;
39
40 [[noreturn]] TC_COMMON_API void AbortHandler(int sigval) noexcept;
41
42 namespace Impl
43 {
44 template <typename T>
45 inline T* AssertNotNull(T* pointer, char const* file, int line, char const* function, char const* message) noexcept
46 {
47 if (pointer) [[likely]]
48 return pointer;
49
50 Assert(file, line, function, message, ::GetDebugInfo());
51 }
52 }
53} // namespace Trinity
54
55#if TRINITY_COMPILER == TRINITY_COMPILER_MICROSOFT
56#define ASSERT_BEGIN __pragma(warning(push)) __pragma(warning(disable: 4127))
57#define ASSERT_END __pragma(warning(pop))
58#else
59#define ASSERT_BEGIN
60#define ASSERT_END
61#endif
62
63#if TRINITY_PLATFORM == TRINITY_PLATFORM_WINDOWS
64#define EXCEPTION_ASSERTION_FAILURE 0xC0000420L
65#endif
66
67#define WPAssert(cond, ...) ASSERT_BEGIN do { if (!(cond)) [[unlikely]] Trinity::Assert(__FILE__, __LINE__, __FUNCTION__, #cond, GetDebugInfo(), ##__VA_ARGS__); } while(0) ASSERT_END
68#define WPAssert_NODEBUGINFO(cond, ...) ASSERT_BEGIN do { if (!(cond)) [[unlikely]] Trinity::Assert(__FILE__, __LINE__, __FUNCTION__, #cond, ::GetDebugInfo(), ##__VA_ARGS__); } while(0) ASSERT_END
69#define WPFatal(cond, ...) ASSERT_BEGIN do { if (!(cond)) [[unlikely]] Trinity::Fatal(__FILE__, __LINE__, __FUNCTION__, ##__VA_ARGS__); } while(0) ASSERT_END
70#define WPError(cond, msg) ASSERT_BEGIN do { if (!(cond)) [[unlikely]] Trinity::Error(__FILE__, __LINE__, __FUNCTION__, (msg)); } while(0) ASSERT_END
71#define WPWarning(cond, msg) ASSERT_BEGIN do { if (!(cond)) [[unlikely]] Trinity::Warning(__FILE__, __LINE__, __FUNCTION__, (msg)); } while(0) ASSERT_END
72#define WPAbort() ASSERT_BEGIN do { Trinity::Abort(__FILE__, __LINE__, __FUNCTION__); } while(0) ASSERT_END
73#define WPAbort_MSG(msg, ...) ASSERT_BEGIN do { Trinity::Abort(__FILE__, __LINE__, __FUNCTION__, (msg), ##__VA_ARGS__); } while(0) ASSERT_END
74
75#ifdef PERFORMANCE_PROFILING
76#define ASSERT(cond, ...) ((void)0)
77#define ASSERT_NODEBUGINFO(cond, ...) ((void)0)
78#define ASSERT_NOTNULL(pointer) (pointer)
79#else
80#define ASSERT WPAssert
81#define ASSERT_NODEBUGINFO WPAssert_NODEBUGINFO
82#define ASSERT_NOTNULL(pointer) Trinity::Impl::AssertNotNull(pointer, __FILE__, __LINE__, __FUNCTION__, #pointer)
83#endif
84
85#define ASSERT_WITH_SIDE_EFFECTS WPAssert
86
87#define ABORT WPAbort
88#define ABORT_MSG WPAbort_MSG
89
90#endif
#define TC_COMMON_API
Definition Define.h:99
#define ATTR_PRINTF(F, V)
COREDEBUG.
Definition Define.h:78
std::string GetDebugInfo()
Definition Errors.cpp:170
TC_COMMON_API std::string GetDebugInfo()
Definition Errors.cpp:170
T * AssertNotNull(T *pointer, char const *file, int line, char const *function, char const *message) noexcept
Definition Errors.h:45
void Assert(char const *file, int line, char const *function, char const *message, std::string debugInfo) noexcept
Definition Errors.cpp:76
void Error(char const *file, int line, char const *function, char const *message) noexcept
Definition Errors.cpp:121
void Abort(char const *file, int line, char const *function) noexcept
Definition Errors.cpp:135
void Fatal(char const *file, int line, char const *function, char const *message,...) noexcept
Definition Errors.cpp:103
void AbortHandler(int sigval) noexcept
Definition Errors.cpp:160