comparison ErrorHandling.h @ 1545:c4ab816fcc5e

assert, Abortf, AbortWithError -> Assert, Error refactors here and there
author Nomad
date Sat, 07 Sep 2013 20:05:20 +0200
parents
children 30db6d265ceb
comparison
equal deleted inserted replaced
1544:499761153844 1545:c4ab816fcc5e
1 #pragma once
2
3 #define Error(format, ...) Error_impl_(__FILE__, __FUNCTION__, __LINE__, format, __VA_ARGS__)
4 #define Assert(condition, format, ...) Assert_impl_(__FILE__, __FUNCTION__, __LINE__, condition, #condition, format, __VA_ARGS__)
5 #define Assert(condition) Assert_impl_(__FILE__, __FUNCTION__, __LINE__, condition, #condition, nullptr)
6
7
8
9
10 #include <stdarg.h>
11 inline __declspec(noreturn) void Error_impl_(const char *filename, const char *functionname, int line,
12 const char *format, ...)
13 {
14 va_list va;
15 va_start(va, format);
16 {
17 char header[4096];
18 sprintf(header, "Error in %s: %u\n\t%s\n\n", filename, line, functionname);
19
20 char msg_body[8192];
21 vsprintf(msg_body, format, va);
22
23 wchar_t msg[sizeof(header) + sizeof(msg_body)];
24 swprintf(msg, L"%S %S", header, msg_body);
25
26 extern void MsgBox(const wchar_t *, const wchar_t *);
27 MsgBox(msg, L"Error");
28 }
29 va_end(va);
30
31 __debugbreak();
32 }
33
34
35 inline void Assert_impl_(const char *filename, const char *functionname, int line,
36 bool condition, const char *condition_string, const char *format, ...)
37 {
38 if (condition)
39 return;
40
41 va_list va;
42 va_start(va, format);
43 {
44 char header[4096];
45 sprintf(header, "Assertion in %s: %u\n\t%s:\n%s\n\n", filename, line, functionname, condition_string);
46
47 char msg_body[8192];
48 vsprintf(msg_body, format, va);
49
50 wchar_t msg[sizeof(header) + sizeof(msg_body)];
51 if (format)
52 swprintf(msg, L"%S %S", header, msg_body);
53 else
54 swprintf(msg, L"%S", header);
55
56 extern void MsgBox(const wchar_t *, const wchar_t *);
57 MsgBox(msg, L"Assertion");
58 }
59 va_end(va);
60
61 __debugbreak();
62 }