/[ascend]/trunk/base/generic/utilities/ascPanic.h
ViewVC logotype

Contents of /trunk/base/generic/utilities/ascPanic.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 778 - (show annotations) (download) (as text)
Tue Jul 18 05:10:03 2006 UTC (13 years, 6 months ago) by johnpye
File MIME type: text/x-chdr
File size: 4689 byte(s)
Working to fix the 'NORETURN' stuff so that it works on both MSVC++ and GCC and fails
gracefully elsewhere.
1 /*
2 ASCEND Language Interpreter
3 AscPanic by Mark Thomas, created 15 May 1997
4 Copyright (C) 2005 Carnegie-Mellon University
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 This file is part of the SLV solver.
20 */
21
22 /** @file
23 Ascend Panic - fatal error handling.
24
25 Requires
26 #include <stdarg.h>
27 #include "utilities/ascConfig.h"
28 */
29
30 /* removed changelog -- see ViewCVS for full history */
31
32 #ifndef ASC_ASCPANIC_H
33 #define ASC_ASCPANIC_H
34
35 /**
36 Our assert macro. Uses Asc_Panic() to report & handle assertion failure. Disabled if ASC_NO_ASSERTIONS is defined.
37 */
38 #ifdef ASC_NO_ASSERTIONS
39 # define asc_assert(x) ((void)0)
40 #else
41 # define asc_assert(cond) \
42 ((cond) ? (void)0 : Asc_Panic(ASCERR_ASSERTION_FAILED, NULL, \
43 "Assertion failed in %s:%d: '%s'", __FILE__, __LINE__, #cond))
44 #endif
45
46 NORETURN ASC_DLLSPEC(void) Asc_Panic(
47 CONST int status, CONST char *function,
48 CONST char *format, ...
49 );
50 /**< Print fatal error message, run callback function & (usually) exit the program.
51
52 @param status Status code passed by the calling function.
53 @param function Pointer to the name of the calling function.
54 @param format printf-style format string for VAR_ARGS to follow.
55
56 This is the fatal error handler for the ASCEND system. It prints
57 the printf-style variable arguments using the specified format to
58 ASCERR file handle. The message is formatted with a header
59 (e.g. 'ASCEND PANIC!!) and the name of the function (if non-NULL),
60 followed by the variables & format passed as arguments. ASCERR
61 should have been initialized to a valid file stream or else the
62 message will not be printed (checked by assertion). @par
63
64 If a valid file name has been previously set using
65 Asc_PanicSetOutfile(), the message is printed to this file also.
66 Under Windows, a MessageBox will also be displayed with the
67 message. @par
68
69 If a callback has been set using Asc_PanicSetCallback(), the
70 registered function will be called with the specified status.
71 If the callback returns non-NULL, then exit() is called to end
72 the program. This is the default behavior. If the callback
73 is able to resolve the problem, then it should return zero and
74 Asc_Panic() will just return. This will be useful mostly for
75 testing purposes, and should be used with caution.
76 */
77
78 ASC_DLLSPEC(void ) Asc_PanicSetOutfile(CONST char *filename);
79 /**< Sets a file name for reporting of Asc_Panic() messages.
80
81 @param filename Pointer to the name of the file to print messages to.
82
83 Calling this function with a non-NULL "filename" will cause
84 Asc_Panic() to write panic messages to "filename" in addition to the
85 ASCERR file handle. Passing in a "filename" of NULL causes panic
86 messages not to be written to disk---this undoes the effect of
87 previous calls to Asc_PanicSetOutfile().
88 */
89
90 typedef int (*PanicCallbackFunc)(int);
91 /**< Signature of the callback function called by Asc_Panic().
92
93 @param the status code passed to Asc_Panic() by the original caller.
94 @return nonzero if ASCEND should exit, 0 if Asc_Panic should just return.
95
96 This functionality is provided primarily for internal testing
97 purposes. It should be used with extreme caution in release
98 code. Asc_Panic() is called from all over ASCEND for many
99 error conditions, and current calls assume no return.
100 */
101
102 ASC_DLLSPEC(PanicCallbackFunc ) Asc_PanicSetCallback(PanicCallbackFunc func);
103 /**< Registers a callback function to be called by Asc_Panic().
104
105 @param func Pointer to the new function to call during an Asc_Panic().
106 @return A pointer to the previously-registered callback, or NULL
107 if none was registered.
108
109 This allows the user to specify a cleanup function to be
110 called during a fatal error.
111
112 @see PanicCallbackFunc for the form this callback function takes.
113 */
114
115 ASC_DLLSPEC(void ) Asc_PanicDisplayMessageBox(int is_displayed);
116 /**<
117 Controls whether a MessageBox is displayed by Asc_Panic() on Windows.
118
119 @param is_displayed if non-zero, messagebox should be displayed, else not.
120
121 Has no effect on non-Windows platforms.
122 */
123
124 #endif /* ASC_ASCPANIC_H */

john.pye@anu.edu.au
ViewVC Help
Powered by ViewVC 1.1.22