File indexing completed on 2025-08-05 08:09:30
0001
0002
0003
0004
0005
0006
0007
0008
0009 #pragma once
0010 #include <exception>
0011 #include <iostream>
0012 #include <sstream>
0013 #include <string>
0014
0015 namespace Acts {
0016
0017
0018 class AssertionFailureException : public std::exception {
0019 public:
0020
0021 class StreamFormatter {
0022 private:
0023 std::ostringstream stream;
0024
0025 public:
0026
0027 operator std::string() const { return stream.str(); }
0028
0029
0030
0031
0032
0033 template <typename T>
0034 StreamFormatter& operator<<(const T& value) {
0035 stream << value;
0036 return *this;
0037 }
0038 };
0039
0040
0041
0042
0043
0044
0045 AssertionFailureException(const std::string& expression,
0046 const std::string& file, int line,
0047 const std::string& msg) {
0048 std::ostringstream os;
0049
0050 if (!msg.empty()) {
0051 os << msg << ": ";
0052 }
0053
0054 os << "Assertion '" << expression << "'";
0055
0056 os << " failed in file '" << file << "' line " << line;
0057 report = os.str();
0058 }
0059
0060
0061 const char* what() const throw() override { return report.c_str(); }
0062
0063 private:
0064 std::string report;
0065 };
0066
0067 }
0068
0069 #define throw_assert(EXPRESSION, MESSAGE) \
0070 if (!(EXPRESSION)) { \
0071 throw Acts::AssertionFailureException( \
0072 #EXPRESSION, __FILE__, __LINE__, \
0073 (Acts::AssertionFailureException::StreamFormatter() << MESSAGE)); \
0074 }