boost exception test.
[dcpomatic.git] / src / lib / dcpomatic_assert.h
index a9851d0f886c5825a18f97ca9083a180cd1d3f48..b8adc5225202c78529ab47d0e518ff8c06d3034d 100644 (file)
@@ -1,5 +1,5 @@
 /*
-    Copyright (C) 2014 Carl Hetherington <cth@carlh.net>
+    Copyright (C) 2014-2020 Carl Hetherington <cth@carlh.net>
 
     This file is part of DCP-o-matic.
 
 
 */
 
+#ifndef DCPOMATIC_ASSERT_H
+#define DCPOMATIC_ASSERT_H
+
 #include "exceptions.h"
+#include <boost/stacktrace.hpp>
+#include <boost/exception/all.hpp>
+
+typedef boost::error_info<struct tag_stacktrace, boost::stacktrace::stacktrace> traced;
+
+template <class E>
+void throw_with_trace(E const& e)
+{
+       throw boost::enable_error_info(e) << traced(boost::stacktrace::stacktrace());
+}
+
+#define DCPOMATIC_ASSERT(x) if (!(x)) throw_with_trace(ProgrammingError (__FILE__, __LINE__));
+#define DCPOMATIC_ASSERT_MESSAGE(x, m, ...) if (!(x)) throw_with_trace(ProgrammingError(__FILE__, __LINE__, String::compose(m, __VA_ARGS__)));
 
-#define DCPOMATIC_ASSERT(x) if (!(x)) throw ProgrammingError (__FILE__, __LINE__);
+#endif