3 * \file support/lassert.h
5 * This file is part of LyX, the document processor.
6 * Licence details can be found in the file COPYING.
10 * Full author contact details are available in file CREDITS.
18 #include "support/strfwd.h"
22 /******************************************************************************
24 LyX has five different macros that can be used to make assertions. They behave
25 the same way in devel mode: They assert. The differences between them are how
26 they behave in release mode.
28 In order of increasing seriousness, they are:
31 This macro should be used when one just wants to test expr. If devel mode,
32 this will lead to an assertion. In release mode, we will simply continue. So
33 LATTEST should be used only if you know, in advance, that it will be safe to
34 continue with the usual program flow, but failure of expr still means that
35 there is something that needs to be fixed.
38 This macro should be used when a failure of expr is not compatible with
39 continuing the ordinary program flow, but is something from which we can
40 recover. This might mean simply returning early from some routine; it might
41 mean resetting some variables to values known to be sane; it might mean
42 taking some other corrective action.
45 This macro should be used when a failure of expr indicates that the current
46 operation cannot safely be completed. In release mode, it will abort that
47 operation and print a warning message to the user.
50 This macro should be used when a failure of expr indicates a problem with a
51 Buffer or its related objects, e.g., a Cursor. In release mode, it throws a
52 BufferException, which will typically result in an emergency save of that
56 This macro should be used if a failure of expr is incompatible with LyX
57 continuing to operate at all. In release mode, this issues an ErrorException,
58 which typically results in an emergency shutdown.
60 ******************************************************************************/
63 void doAssert(char const * expr, char const * file, long line);
64 void doWarnIf(char const * expr, char const * file, long line);
65 void doBufErr(char const * expr, char const * file, long line);
66 void doAppErr(char const * expr, char const * file, long line);
68 /// Print demangled callstack to stderr
69 void printCallStack();
74 #define LATTEST(expr) \
75 if (expr) {} else { lyx::doAssert(#expr, __FILE__, __LINE__); }
77 #define LASSERT(expr, escape) \
78 if (expr) {} else { lyx::doAssert(#expr, __FILE__, __LINE__); escape; }
80 #define LWARNIF(expr) \
81 if (expr) {} else { lyx::doWarnIf(#expr, __FILE__, __LINE__); }
83 #define LBUFERR(expr) \
84 if (expr) {} else { lyx::doBufErr(#expr, __FILE__, __LINE__); }
86 #define LAPPERR(expr) \
87 if (expr) {} else { lyx::doAppErr(#expr, __FILE__, __LINE__); }