2013-04-07 00:19:45 +00:00
|
|
|
|
2008-04-12 15:11:59 +00:00
|
|
|
/**
|
2008-04-30 08:26:40 +00:00
|
|
|
* \file support/lassert.h
|
2008-04-12 15:11:59 +00:00
|
|
|
*
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
*
|
2008-11-14 15:58:50 +00:00
|
|
|
* \author André Pönitz
|
2008-04-12 15:11:59 +00:00
|
|
|
*
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef LASSERT_H
|
|
|
|
#define LASSERT_H
|
|
|
|
|
2008-04-29 14:56:27 +00:00
|
|
|
#ifdef __cplusplus
|
2013-04-07 00:19:45 +00:00
|
|
|
|
|
|
|
#include "support/strfwd.h"
|
|
|
|
|
2008-04-12 15:11:59 +00:00
|
|
|
namespace lyx {
|
|
|
|
|
2013-04-07 00:19:45 +00:00
|
|
|
/******************************************************************************
|
|
|
|
|
2014-03-26 19:17:57 +00:00
|
|
|
LyX has five different macros that can be used to make assertions. They behave
|
2013-04-07 00:19:45 +00:00
|
|
|
the same way in devel mode: They assert. The differences between them are how
|
|
|
|
they behave in release mode.
|
|
|
|
|
|
|
|
In order of increasing seriousness, they are:
|
|
|
|
|
|
|
|
LATTEST(expr)
|
|
|
|
This macro should be used when one just wants to test expr. If devel mode,
|
|
|
|
this will lead to an assertion. In release mode, we will simply continue. So
|
|
|
|
LATTEST should be used only if you know, in advance, that it will be safe to
|
|
|
|
continue with the usual program flow, but failure of expr still means that
|
|
|
|
there is something that needs to be fixed.
|
|
|
|
|
|
|
|
LASSERT(expr, escape)
|
|
|
|
This macro should be used when a failure of expr is not compatible with
|
|
|
|
continuing the ordinary program flow, but is something from which we can
|
|
|
|
recover. This might mean simply returning early from some routine; it might
|
|
|
|
mean resetting some variables to values known to be sane; it might mean
|
|
|
|
taking some other corrective action.
|
|
|
|
|
2013-04-27 21:52:55 +00:00
|
|
|
LWARNIF(expr)
|
2013-04-07 00:19:45 +00:00
|
|
|
This macro should be used when a failure of expr indicates that the current
|
|
|
|
operation cannot safely be completed. In release mode, it will abort that
|
|
|
|
operation and print a warning message to the user.
|
|
|
|
|
2013-04-27 21:52:55 +00:00
|
|
|
LBUFERR(expr)
|
2013-04-07 00:19:45 +00:00
|
|
|
This macro should be used when a failure of expr indicates a problem with a
|
|
|
|
Buffer or its related objects, e.g., a Cursor. In release mode, it throws a
|
|
|
|
BufferException, which will typically result in an emergency save of that
|
2013-04-28 16:08:30 +00:00
|
|
|
particular Buffer.
|
2013-04-07 00:19:45 +00:00
|
|
|
|
2013-04-27 21:52:55 +00:00
|
|
|
LAPPERR(expr)
|
2013-04-07 00:19:45 +00:00
|
|
|
This macro should be used if a failure of expr is incompatible with LyX
|
|
|
|
continuing to operate at all. In release mode, this issues an ErrorException,
|
2013-04-28 16:08:30 +00:00
|
|
|
which typically results in an emergency shutdown.
|
2013-04-07 00:19:45 +00:00
|
|
|
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
|
2008-04-12 15:11:59 +00:00
|
|
|
void doAssert(char const * expr, char const * file, long line);
|
2013-04-27 21:52:55 +00:00
|
|
|
void doWarnIf(char const * expr, char const * file, long line);
|
|
|
|
void doBufErr(char const * expr, char const * file, long line);
|
|
|
|
void doAppErr(char const * expr, char const * file, long line);
|
2008-04-12 15:11:59 +00:00
|
|
|
|
2011-04-25 09:14:50 +00:00
|
|
|
/// Print demangled callstack to stderr
|
2014-06-07 09:12:31 +00:00
|
|
|
docstring printCallStack();
|
2011-04-25 09:14:50 +00:00
|
|
|
|
|
|
|
|
2008-04-12 15:11:59 +00:00
|
|
|
} // namespace lyx
|
|
|
|
|
2013-04-07 00:19:45 +00:00
|
|
|
#define LATTEST(expr) \
|
|
|
|
if (expr) {} else { lyx::doAssert(#expr, __FILE__, __LINE__); }
|
|
|
|
|
2008-04-12 15:11:59 +00:00
|
|
|
#define LASSERT(expr, escape) \
|
|
|
|
if (expr) {} else { lyx::doAssert(#expr, __FILE__, __LINE__); escape; }
|
|
|
|
|
2013-04-27 21:52:55 +00:00
|
|
|
#define LWARNIF(expr) \
|
|
|
|
if (expr) {} else { lyx::doWarnIf(#expr, __FILE__, __LINE__); }
|
2013-04-07 00:19:45 +00:00
|
|
|
|
2013-04-27 21:52:55 +00:00
|
|
|
#define LBUFERR(expr) \
|
|
|
|
if (expr) {} else { lyx::doBufErr(#expr, __FILE__, __LINE__); }
|
2013-04-07 00:19:45 +00:00
|
|
|
|
2013-04-27 21:52:55 +00:00
|
|
|
#define LAPPERR(expr) \
|
|
|
|
if (expr) {} else { lyx::doAppErr(#expr, __FILE__, __LINE__); }
|
2013-04-07 00:19:45 +00:00
|
|
|
|
|
|
|
#endif
|
2008-04-12 15:11:59 +00:00
|
|
|
#endif // LASSERT
|