/*
- 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