Mercurial > mm7
annotate ErrorHandling.h @ 2465:b054ea5daf45
cleaning project part 3
author | zipi |
---|---|
date | Sun, 17 Aug 2014 20:23:06 +0100 |
parents | 1d04e48651d4 |
children |
rev | line source |
---|---|
2253
aff7a7b072b7
adding _CRT_SECURE_NO_WARNINGS to get rid of a few hundrer annoying warnings + adding count parameter to swprintf
Grumpy7
parents:
1558
diff
changeset
|
1 #define _CRT_NON_CONFORMING_SWPRINTFS |
1545 | 2 #pragma once |
3 | |
4 #define Error(format, ...) Error_impl_(__FILE__, __FUNCTION__, __LINE__, format, __VA_ARGS__) | |
1558
30db6d265ceb
Changed the new Assert macro definition slightly, Party::AddItem (for some reason in players.cpp) renamed to Party::AddItemToParty, cleaned up; some unused variables in previous functions removed
Grumpy7
parents:
1545
diff
changeset
|
5 #define Assert(condition, ...) Assert_impl_(__FILE__, __FUNCTION__, __LINE__, condition, #condition, __VA_ARGS__) |
1545 | 6 |
7 | |
8 | |
9 #include <stdarg.h> | |
2336 | 10 #include <stdio.h> |
1545 | 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)]; | |
2253
aff7a7b072b7
adding _CRT_SECURE_NO_WARNINGS to get rid of a few hundrer annoying warnings + adding count parameter to swprintf
Grumpy7
parents:
1558
diff
changeset
|
24 swprintf(msg, 8192, L"%S %S", header, msg_body); |
1545 | 25 |
26 extern void MsgBox(const wchar_t *, const wchar_t *); | |
27 MsgBox(msg, L"Error"); | |
28 } | |
29 va_end(va); | |
30 | |
2462
1d04e48651d4
Render split into interface and realization, added Direct3D 11
a.parshin
parents:
2336
diff
changeset
|
31 #ifndef NODEBUG |
1d04e48651d4
Render split into interface and realization, added Direct3D 11
a.parshin
parents:
2336
diff
changeset
|
32 __debugbreak(); |
1d04e48651d4
Render split into interface and realization, added Direct3D 11
a.parshin
parents:
2336
diff
changeset
|
33 #endif |
1d04e48651d4
Render split into interface and realization, added Direct3D 11
a.parshin
parents:
2336
diff
changeset
|
34 exit(0); |
1545 | 35 } |
36 | |
37 | |
38 inline void Assert_impl_(const char *filename, const char *functionname, int line, | |
1558
30db6d265ceb
Changed the new Assert macro definition slightly, Party::AddItem (for some reason in players.cpp) renamed to Party::AddItemToParty, cleaned up; some unused variables in previous functions removed
Grumpy7
parents:
1545
diff
changeset
|
39 bool condition, const char *condition_string, const char *format = nullptr, ...) |
1545 | 40 { |
41 if (condition) | |
42 return; | |
43 | |
44 va_list va; | |
45 va_start(va, format); | |
46 { | |
47 char header[4096]; | |
48 sprintf(header, "Assertion in %s: %u\n\t%s:\n%s\n\n", filename, line, functionname, condition_string); | |
49 | |
50 char msg_body[8192]; | |
51 vsprintf(msg_body, format, va); | |
52 | |
53 wchar_t msg[sizeof(header) + sizeof(msg_body)]; | |
54 if (format) | |
2253
aff7a7b072b7
adding _CRT_SECURE_NO_WARNINGS to get rid of a few hundrer annoying warnings + adding count parameter to swprintf
Grumpy7
parents:
1558
diff
changeset
|
55 swprintf(msg, (sizeof(header) + sizeof(msg_body)), L"%S %S", header, msg_body); |
1545 | 56 else |
2253
aff7a7b072b7
adding _CRT_SECURE_NO_WARNINGS to get rid of a few hundrer annoying warnings + adding count parameter to swprintf
Grumpy7
parents:
1558
diff
changeset
|
57 swprintf(msg, (sizeof(header) + sizeof(msg_body)), L"%S", header); |
1545 | 58 |
59 extern void MsgBox(const wchar_t *, const wchar_t *); | |
60 MsgBox(msg, L"Assertion"); | |
61 } | |
62 va_end(va); | |
63 | |
64 __debugbreak(); | |
65 } |