File: errorhandler.h

package info (click to toggle)
spring 104.0%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 47,512 kB
  • sloc: cpp: 391,093; ansic: 79,943; python: 12,356; java: 12,201; awk: 5,889; sh: 1,826; xml: 655; makefile: 486; perl: 405; php: 211; objc: 194; sed: 2
file content (93 lines) | stat: -rw-r--r-- 4,366 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/* This file is part of the Spring engine (GPL v2 or later), see LICENSE.html */

/**
 * @brief error messages
 * Platform specific error handling
 */

#ifndef _ERROR_HANDLER_H
#define _ERROR_HANDLER_H

#include <string>
#ifndef NO_CATCH_EXCEPTIONS
#include <sstream>
#endif
#include "System/Exceptions.h"

#define MBF_OK    1
#define MBF_INFO  2
#define MBF_EXCL  4
#define MBF_CRASH 8

// legacy support define
#define handleerror(o, m, c, f) ErrorMessageBox(m, c, f)

/**
 * Will pop up an error message window and exit (C version).
 * @param  msg     the main text, describing the error
 * @param  caption will appear in the title bar of the error window
 * @param  flags   one of:
 *                 - MBF_OK   : Error
 *                 - MBF_EXCL : Warning
 *                 - MBF_INFO : Info
 *                 - MBF_CRASH: Crash
 */
void ErrorMessageBox(const std::string& msg, const std::string& caption, unsigned int flags = MBF_OK);


/**
 * Spring's common exception handler.
 */
#define CATCH_SPRING_ERRORS_BASE                                                             \
	catch (const content_error& e) {                                                         \
		ErrorMessageBox(e.what(), "Spring: caught content_error: ", MBF_OK | MBF_EXCL);      \
	}                                                                                        \
	catch (const opengl_error& e) {                                                          \
		ErrorMessageBox(e.what(), "Spring: caught opengl_error: ", MBF_OK | MBF_CRASH);      \
	}                                                                                        \
	catch (const user_error& e) {                                                            \
		ErrorMessageBox(e.what(), "Spring: caught user_error: ", MBF_OK | MBF_EXCL);         \
	}                                                                                        \
	catch (const unsupported_error& e) {                                                     \
		ErrorMessageBox(e.what(), "Spring: caught unsupported_error: ", MBF_OK | MBF_CRASH); \
	}                                                                                        \
	catch (const network_error& e) {                                                         \
		ErrorMessageBox(e.what(), "Spring: caught network_error: ", MBF_OK | MBF_EXCL);      \
	}

/**
 * Spring's exception handler additions to BASE for non DEBUG builds.
 */
#define CATCH_SPRING_ERRORS_EXTENDED                                                          \
	catch (const std::logic_error& e) {                                                       \
		ErrorMessageBox(e.what(), "Spring: caught std::logic_error", MBF_OK | MBF_CRASH);     \
	}                                                                                         \
	catch (const std::bad_alloc& e) {                                                         \
		ErrorMessageBox(e.what(), "Spring: caught std::bad_alloc", MBF_OK | MBF_CRASH);       \
	}                                                                                         \
	catch (const std::system_error& e) {                                                      \
		ErrorMessageBox(e.what(), "Spring: caught std::system_error", MBF_OK | MBF_CRASH);    \
	}                                                                                         \
	catch (const std::runtime_error& e) {                                                     \
		ErrorMessageBox(e.what(), "Spring: caught std::runtime_error", MBF_OK | MBF_CRASH);   \
	}                                                                                         \
	catch (const std::exception& e) {                                                         \
		ErrorMessageBox(e.what(), "Spring: caught std::exception", MBF_OK | MBF_CRASH);       \
	}                                                                                         \
	catch (const char* e) {                                                                   \
		ErrorMessageBox(e, "Spring: caught legacy exception", MBF_OK | MBF_CRASH);            \
	}

/**
 * Spring's common error handler.
 */
#ifdef NO_CATCH_EXCEPTIONS
	#define CATCH_SPRING_ERRORS \
		CATCH_SPRING_ERRORS_BASE
#else
	#define CATCH_SPRING_ERRORS \
		CATCH_SPRING_ERRORS_BASE \
		CATCH_SPRING_ERRORS_EXTENDED
#endif

#endif // _ERROR_HANDLER_H