annotate ErrorHandling.h @ 1857:f357e4cbd169

Actor::AI_SpellAttack moved spells into a huge case
author Grumpy7
date Mon, 14 Oct 2013 00:58:05 +0200
parents 30db6d265ceb
children aff7a7b072b7
rev   line source
1545
c4ab816fcc5e assert, Abortf, AbortWithError -> Assert, Error
Nomad
parents:
diff changeset
1 #pragma once
c4ab816fcc5e assert, Abortf, AbortWithError -> Assert, Error
Nomad
parents:
diff changeset
2
c4ab816fcc5e assert, Abortf, AbortWithError -> Assert, Error
Nomad
parents:
diff changeset
3 #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
4 #define Assert(condition, ...) Assert_impl_(__FILE__, __FUNCTION__, __LINE__, condition, #condition, __VA_ARGS__)
1545
c4ab816fcc5e assert, Abortf, AbortWithError -> Assert, Error
Nomad
parents:
diff changeset
5
c4ab816fcc5e assert, Abortf, AbortWithError -> Assert, Error
Nomad
parents:
diff changeset
6
c4ab816fcc5e assert, Abortf, AbortWithError -> Assert, Error
Nomad
parents:
diff changeset
7
c4ab816fcc5e assert, Abortf, AbortWithError -> Assert, Error
Nomad
parents:
diff changeset
8 #include <stdarg.h>
c4ab816fcc5e assert, Abortf, AbortWithError -> Assert, Error
Nomad
parents:
diff changeset
9 inline __declspec(noreturn) void Error_impl_(const char *filename, const char *functionname, int line,
c4ab816fcc5e assert, Abortf, AbortWithError -> Assert, Error
Nomad
parents:
diff changeset
10 const char *format, ...)
c4ab816fcc5e assert, Abortf, AbortWithError -> Assert, Error
Nomad
parents:
diff changeset
11 {
c4ab816fcc5e assert, Abortf, AbortWithError -> Assert, Error
Nomad
parents:
diff changeset
12 va_list va;
c4ab816fcc5e assert, Abortf, AbortWithError -> Assert, Error
Nomad
parents:
diff changeset
13 va_start(va, format);
c4ab816fcc5e assert, Abortf, AbortWithError -> Assert, Error
Nomad
parents:
diff changeset
14 {
c4ab816fcc5e assert, Abortf, AbortWithError -> Assert, Error
Nomad
parents:
diff changeset
15 char header[4096];
c4ab816fcc5e assert, Abortf, AbortWithError -> Assert, Error
Nomad
parents:
diff changeset
16 sprintf(header, "Error in %s: %u\n\t%s\n\n", filename, line, functionname);
c4ab816fcc5e assert, Abortf, AbortWithError -> Assert, Error
Nomad
parents:
diff changeset
17
c4ab816fcc5e assert, Abortf, AbortWithError -> Assert, Error
Nomad
parents:
diff changeset
18 char msg_body[8192];
c4ab816fcc5e assert, Abortf, AbortWithError -> Assert, Error
Nomad
parents:
diff changeset
19 vsprintf(msg_body, format, va);
c4ab816fcc5e assert, Abortf, AbortWithError -> Assert, Error
Nomad
parents:
diff changeset
20
c4ab816fcc5e assert, Abortf, AbortWithError -> Assert, Error
Nomad
parents:
diff changeset
21 wchar_t msg[sizeof(header) + sizeof(msg_body)];
c4ab816fcc5e assert, Abortf, AbortWithError -> Assert, Error
Nomad
parents:
diff changeset
22 swprintf(msg, L"%S %S", header, msg_body);
c4ab816fcc5e assert, Abortf, AbortWithError -> Assert, Error
Nomad
parents:
diff changeset
23
c4ab816fcc5e assert, Abortf, AbortWithError -> Assert, Error
Nomad
parents:
diff changeset
24 extern void MsgBox(const wchar_t *, const wchar_t *);
c4ab816fcc5e assert, Abortf, AbortWithError -> Assert, Error
Nomad
parents:
diff changeset
25 MsgBox(msg, L"Error");
c4ab816fcc5e assert, Abortf, AbortWithError -> Assert, Error
Nomad
parents:
diff changeset
26 }
c4ab816fcc5e assert, Abortf, AbortWithError -> Assert, Error
Nomad
parents:
diff changeset
27 va_end(va);
c4ab816fcc5e assert, Abortf, AbortWithError -> Assert, Error
Nomad
parents:
diff changeset
28
c4ab816fcc5e assert, Abortf, AbortWithError -> Assert, Error
Nomad
parents:
diff changeset
29 __debugbreak();
c4ab816fcc5e assert, Abortf, AbortWithError -> Assert, Error
Nomad
parents:
diff changeset
30 }
c4ab816fcc5e assert, Abortf, AbortWithError -> Assert, Error
Nomad
parents:
diff changeset
31
c4ab816fcc5e assert, Abortf, AbortWithError -> Assert, Error
Nomad
parents:
diff changeset
32
c4ab816fcc5e assert, Abortf, AbortWithError -> Assert, Error
Nomad
parents:
diff changeset
33 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
34 bool condition, const char *condition_string, const char *format = nullptr, ...)
1545
c4ab816fcc5e assert, Abortf, AbortWithError -> Assert, Error
Nomad
parents:
diff changeset
35 {
c4ab816fcc5e assert, Abortf, AbortWithError -> Assert, Error
Nomad
parents:
diff changeset
36 if (condition)
c4ab816fcc5e assert, Abortf, AbortWithError -> Assert, Error
Nomad
parents:
diff changeset
37 return;
c4ab816fcc5e assert, Abortf, AbortWithError -> Assert, Error
Nomad
parents:
diff changeset
38
c4ab816fcc5e assert, Abortf, AbortWithError -> Assert, Error
Nomad
parents:
diff changeset
39 va_list va;
c4ab816fcc5e assert, Abortf, AbortWithError -> Assert, Error
Nomad
parents:
diff changeset
40 va_start(va, format);
c4ab816fcc5e assert, Abortf, AbortWithError -> Assert, Error
Nomad
parents:
diff changeset
41 {
c4ab816fcc5e assert, Abortf, AbortWithError -> Assert, Error
Nomad
parents:
diff changeset
42 char header[4096];
c4ab816fcc5e assert, Abortf, AbortWithError -> Assert, Error
Nomad
parents:
diff changeset
43 sprintf(header, "Assertion in %s: %u\n\t%s:\n%s\n\n", filename, line, functionname, condition_string);
c4ab816fcc5e assert, Abortf, AbortWithError -> Assert, Error
Nomad
parents:
diff changeset
44
c4ab816fcc5e assert, Abortf, AbortWithError -> Assert, Error
Nomad
parents:
diff changeset
45 char msg_body[8192];
c4ab816fcc5e assert, Abortf, AbortWithError -> Assert, Error
Nomad
parents:
diff changeset
46 vsprintf(msg_body, format, va);
c4ab816fcc5e assert, Abortf, AbortWithError -> Assert, Error
Nomad
parents:
diff changeset
47
c4ab816fcc5e assert, Abortf, AbortWithError -> Assert, Error
Nomad
parents:
diff changeset
48 wchar_t msg[sizeof(header) + sizeof(msg_body)];
c4ab816fcc5e assert, Abortf, AbortWithError -> Assert, Error
Nomad
parents:
diff changeset
49 if (format)
c4ab816fcc5e assert, Abortf, AbortWithError -> Assert, Error
Nomad
parents:
diff changeset
50 swprintf(msg, L"%S %S", header, msg_body);
c4ab816fcc5e assert, Abortf, AbortWithError -> Assert, Error
Nomad
parents:
diff changeset
51 else
c4ab816fcc5e assert, Abortf, AbortWithError -> Assert, Error
Nomad
parents:
diff changeset
52 swprintf(msg, L"%S", header);
c4ab816fcc5e assert, Abortf, AbortWithError -> Assert, Error
Nomad
parents:
diff changeset
53
c4ab816fcc5e assert, Abortf, AbortWithError -> Assert, Error
Nomad
parents:
diff changeset
54 extern void MsgBox(const wchar_t *, const wchar_t *);
c4ab816fcc5e assert, Abortf, AbortWithError -> Assert, Error
Nomad
parents:
diff changeset
55 MsgBox(msg, L"Assertion");
c4ab816fcc5e assert, Abortf, AbortWithError -> Assert, Error
Nomad
parents:
diff changeset
56 }
c4ab816fcc5e assert, Abortf, AbortWithError -> Assert, Error
Nomad
parents:
diff changeset
57 va_end(va);
c4ab816fcc5e assert, Abortf, AbortWithError -> Assert, Error
Nomad
parents:
diff changeset
58
c4ab816fcc5e assert, Abortf, AbortWithError -> Assert, Error
Nomad
parents:
diff changeset
59 __debugbreak();
c4ab816fcc5e assert, Abortf, AbortWithError -> Assert, Error
Nomad
parents:
diff changeset
60 }