TrinityCore
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
24namespace Trinity
25{
26 [[noreturn]] TC_COMMON_API void Assert(char const* file, int line, char const* function, std::string debugInfo, char const* message);
27 [[noreturn]] TC_COMMON_API void Assert(char const* file, int line, char const* function, std::string debugInfo, char const* message, char const* format, ...) ATTR_PRINTF(6, 7);
28
29 [[noreturn]] TC_COMMON_API void Fatal(char const* file, int line, char const* function, char const* message, ...) ATTR_PRINTF(4, 5);
30
31 [[noreturn]] TC_COMMON_API void Error(char const* file, int line, char const* function, char const* message);
32
33 [[noreturn]] TC_COMMON_API void Abort(char const* file, int line, char const* function);
34 [[noreturn]] TC_COMMON_API void Abort(char const* file, int line, char const* function, char const* message, ...);
35
36 TC_COMMON_API void Warning(char const* file, int line, char const* function, char const* message);
37
38 [[noreturn]] TC_COMMON_API void AbortHandler(int sigval);
39
40} // namespace Trinity
41
43
44#if TRINITY_COMPILER == TRINITY_COMPILER_MICROSOFT
45#define ASSERT_BEGIN __pragma(warning(push)) __pragma(warning(disable: 4127))
46#define ASSERT_END __pragma(warning(pop))
47#else
48#define ASSERT_BEGIN
49#define ASSERT_END
50#endif
51
52#if TRINITY_PLATFORM == TRINITY_PLATFORM_WINDOWS
53#define EXCEPTION_ASSERTION_FAILURE 0xC0000420L
54#endif
55
56#define WPAssert(cond, ...) ASSERT_BEGIN do { if (!(cond)) [[unlikely]] Trinity::Assert(__FILE__, __LINE__, __FUNCTION__, GetDebugInfo(), #cond, ##__VA_ARGS__); } while(0) ASSERT_END
57#define WPAssert_NODEBUGINFO(cond, ...) ASSERT_BEGIN do { if (!(cond)) [[unlikely]] Trinity::Assert(__FILE__, __LINE__, __FUNCTION__, "", #cond, ##__VA_ARGS__); } while(0) ASSERT_END
58#define WPFatal(cond, ...) ASSERT_BEGIN do { if (!(cond)) [[unlikely]] Trinity::Fatal(__FILE__, __LINE__, __FUNCTION__, ##__VA_ARGS__); } while(0) ASSERT_END
59#define WPError(cond, msg) ASSERT_BEGIN do { if (!(cond)) [[unlikely]] Trinity::Error(__FILE__, __LINE__, __FUNCTION__, (msg)); } while(0) ASSERT_END
60#define WPWarning(cond, msg) ASSERT_BEGIN do { if (!(cond)) [[unlikely]] Trinity::Warning(__FILE__, __LINE__, __FUNCTION__, (msg)); } while(0) ASSERT_END
61#define WPAbort() ASSERT_BEGIN do { Trinity::Abort(__FILE__, __LINE__, __FUNCTION__); } while(0) ASSERT_END
62#define WPAbort_MSG(msg, ...) ASSERT_BEGIN do { Trinity::Abort(__FILE__, __LINE__, __FUNCTION__, (msg), ##__VA_ARGS__); } while(0) ASSERT_END
63
64#ifdef PERFORMANCE_PROFILING
65#define ASSERT(cond, ...) ((void)0)
66#define ASSERT_NODEBUGINFO(cond, ...) ((void)0)
67#else
68#define ASSERT WPAssert
69#define ASSERT_NODEBUGINFO WPAssert_NODEBUGINFO
70#endif
71
72#define ASSERT_WITH_SIDE_EFFECTS WPAssert
73
74#define ABORT WPAbort
75#define ABORT_MSG WPAbort_MSG
76
77template <typename T>
78inline T* ASSERT_NOTNULL_IMPL(T* pointer, char const* expr)
79{
80 ASSERT(pointer, "%s", expr);
81 return pointer;
82}
83
84#define ASSERT_NOTNULL(pointer) ASSERT_NOTNULL_IMPL(pointer, #pointer)
85
86#endif
#define TC_COMMON_API
Definition: Define.h:99
#define ATTR_PRINTF(F, V)
COREDEBUG.
Definition: Define.h:78
T * ASSERT_NOTNULL_IMPL(T *pointer, char const *expr)
Definition: Errors.h:78
TC_COMMON_API std::string GetDebugInfo()
Definition: Errors.cpp:157
#define ASSERT
Definition: Errors.h:68
void Assert(char const *file, int line, char const *function, std::string debugInfo, char const *message)
Definition: Errors.cpp:73
void AbortHandler(int sigval)
Definition: Errors.cpp:146
void Warning(char const *file, int line, char const *function, char const *message)
Definition: Errors.cpp:118
void Abort(char const *file, int line, char const *function)
Definition: Errors.cpp:124
void Fatal(char const *file, int line, char const *function, char const *message,...)
Definition: Errors.cpp:95
void Error(char const *file, int line, char const *function, char const *message)
Definition: Errors.cpp:110
STL namespace.