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. The 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
53 particular Buffer. The msg will be displayed to the user and so should be
57 This macro should be used if a failure of expr is incompatible with LyX
58 continuing to operate at all. In release mode, this issues an ErrorException,
59 which typically results in an emergency shutdown. The msg will be displayed
60 to the user and so should be internationalized.
62 ******************************************************************************/
65 void doAssert(char const * expr, char const * file, long line);
66 void doWarnIf(char const * expr, docstring const & msg, char const * file, long line);
67 void doBufErr(char const * expr, docstring const & msg, char const * file, long line);
68 void doAppErr(char const * expr, docstring const & msg, char const * file, long line);
70 /// Print demangled callstack to stderr
71 void printCallStack();
76 #define LATTEST(expr) \
77 if (expr) {} else { lyx::doAssert(#expr, __FILE__, __LINE__); }
79 #define LASSERT(expr, escape) \
80 if (expr) {} else { lyx::doAssert(#expr, __FILE__, __LINE__); escape; }
82 #define LWARNIF(expr, msg) \
83 if (expr) {} else { lyx::doWarnIf(#expr, msg, __FILE__, __LINE__); }
85 #define LBUFERR(expr, msg) \
86 if (expr) {} else { lyx::doBufErr(#expr, msg, __FILE__, __LINE__); }
88 #define LAPPERR(expr, msg) \
89 if (expr) {} else { lyx::doAppErr(#expr, msg, __FILE__, __LINE__); }