]> git.lyx.org Git - lyx.git/blobdiff - src/support/lassert.cpp
InsetArgument: Set ResetsFontEdit to false
[lyx.git] / src / support / lassert.cpp
index 9c0daff32876de3f9e8d7e1b7048db458da5b6ca..02e64bf7bf681ec9fc84e64d1d5ecb4980e583a1 100644 (file)
 
 #include <config.h>
 
+#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 <boost/assert.hpp>
 
 
 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)
 {
-    // TODO Should we try to print the call stack before exiting?
+       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)
+{
+       docstring const d = _("Assertion %1$s violated in\nfile: %2$s, line: %3$s");
        LYXERR0("ASSERTION " << expr << " VIOLATED IN " << file << ":" << line);
+       
+       return bformat(d, from_ascii(expr), from_ascii(file), 
+               convert<docstring>(line)) + '\n' + msg;
+}
+
+
+void doWarnIf(char const * expr, char const * file, long line)
+{
+       docstring const d = _("It should be safe to continue, but you\nmay wish to save your work and restart LyX.");
+       // comment this out if not needed
+       BOOST_ASSERT(false);
+       throw ExceptionMessage(WarningException, _("Warning!"), 
+               formatHelper(d, expr, file, line));
+}
+
+
+void doBufErr(char const * expr, char const * file, long line)
+{
+       docstring const d = _("There has been an error with this document.\nLyX will attempt to close it safely.");
+       // comment this out if not needed
+       BOOST_ASSERT(false);
+       throw ExceptionMessage(BufferException, _("Buffer Error!"),
+               formatHelper(d, expr, file, line));
+}
+
+
+void doAppErr(char const * expr, char const * file, long line)
+{
+       docstring const d = _("LyX has encountered an application error\nand will now shut down.");
        // comment this out if not needed
        BOOST_ASSERT(false);
+       throw ExceptionMessage(ErrorException, _("Fatal Exception!"),
+               formatHelper(d, expr, file, line));
 }