comparison src/core/panic.h @ 88:44de3c528b63

core: implement basic panic mechanism, continue #2484 @1h
author David Demelier <markand@malikania.fr>
date Thu, 12 Mar 2020 12:44:00 +0100
parents
children e82eca4f8606
comparison
equal deleted inserted replaced
87:ebbf35d90088 88:44de3c528b63
1 /*
2 * panic.h -- unrecoverable error handling
3 *
4 * Copyright (c) 2020 David Demelier <markand@malikania.fr>
5 *
6 * Permission to use, copy, modify, and/or distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
9 *
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 */
18
19 #ifndef MOLKO_PANIC_H
20 #define MOLKO_PANIC_H
21
22 /**
23 * \file panic.h
24 * \brief Unrecoverable error handling.
25 * \ingroup basics
26 *
27 * This set of functions should be used to detect runtime errors that are
28 * unexpected. They should be used only when the game cannot continue because
29 * it is in a unrecoverable state.
30 *
31 * Examples of appropriate use cases:
32 *
33 * - Game saved data is corrupt,
34 * - Assets are missing,
35 * - No more memory.
36 *
37 * In other contexts, use asserts to indicates programming error and
38 * appropriate solutions to recover the game otherwise.
39 */
40
41 #include <stdarg.h>
42
43 /**
44 * \brief Global panic handler.
45 *
46 * The default implementation shows the last error and exit with code 1.
47 */
48 extern void (*panic_handler)(void);
49
50 /**
51 * Terminate the program using the \ref panic_handler routine.
52 *
53 * This function will first set the global error with the provided format
54 * string and then call the handler.
55 *
56 * \pre fmt != NULL
57 * \param fmt the printf(3) format string
58 */
59 void
60 panic(const char *fmt, ...);
61
62 /**
63 * Similar to \ref panic but with a va_list argument instead.
64 *
65 * \pre fmt != NULL
66 * \param fmt the printf(3) format string
67 * \param ap the arguments pointer
68 */
69 void
70 panicv(const char *fmt, va_list ap);
71
72 #endif /* !MOLKO_PANIC_H */