X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Fsupport%2Flassert.cpp;h=048e572871837f1b787aea69a315008c8328e653;hb=62df59cde4847512698e86adb073d526d39c05e1;hp=9c0daff32876de3f9e8d7e1b7048db458da5b6ca;hpb=1d5e483b442885cf67f7ff6d1c505ec7b978e7e1;p=lyx.git diff --git a/src/support/lassert.cpp b/src/support/lassert.cpp index 9c0daff328..048e572871 100644 --- a/src/support/lassert.cpp +++ b/src/support/lassert.cpp @@ -11,7 +11,12 @@ #include +#include "support/convert.h" #include "support/debug.h" +#include "support/docstring.h" +#include "support/ExceptionMessage.h" +#include "support/gettext.h" +#include "support/lstrings.h" #include @@ -28,13 +33,57 @@ namespace lyx { -void doAssert(char const * expr, char const * file, long line) +using namespace std; +using namespace support; + +// TODO Should we try to print the call stack in the course of these? + +void doAssert(char const * expr, char const * file, long line) +{ + LYXERR0("ASSERTION " << expr << " VIOLATED IN " << file << ":" << line); + // comment this out if not needed + BOOST_ASSERT(false); +} + + +docstring formatHelper(docstring const & msg, + char const * expr, char const * file, long line) { - // TODO Should we try to print the call stack before exiting? + static const docstring d = + from_ascii(N_("Assertion %1$s violated in\nfile: %2$s, line: %3$s")); + + return bformat(d, from_ascii(expr), from_ascii(file), + convert(line)) + '\n' + msg; +} + +void doWarnIf(char const * expr, docstring const & msg, char const * file, long line) +{ + LYXERR0("ASSERTION " << expr << " VIOLATED IN " << file << ":" << line); + // comment this out if not needed + BOOST_ASSERT(false); + throw ExceptionMessage(WarningException, _("Warning!"), + formatHelper(msg, expr, file, line)); +} + + +void doBufErr(char const * expr, docstring const & msg, char const * file, long line) +{ + LYXERR0("ASSERTION " << expr << " VIOLATED IN " << file << ":" << line); + // comment this out if not needed + BOOST_ASSERT(false); + throw ExceptionMessage(BufferException, _("Buffer Error!"), + formatHelper(msg, expr, file, line)); +} + + +void doAppErr(char const * expr, docstring const & msg, char const * file, long line) +{ LYXERR0("ASSERTION " << expr << " VIOLATED IN " << file << ":" << line); // comment this out if not needed BOOST_ASSERT(false); + throw ExceptionMessage(ErrorException, _("Fatal Exception!"), + formatHelper(msg, expr, file, line)); }