memgraph/include/utils/exceptions/basic_exception.hpp

38 lines
806 B
C++
Raw Normal View History

#pragma once
#include <stdexcept>
2016-06-15 06:06:21 +08:00
#include <fmt/format.h>
#include "utils/auto_scope.hpp"
#include "utils/stacktrace.hpp"
class BasicException : public std::exception
{
public:
2016-08-02 05:14:09 +08:00
BasicException(const std::string& message) noexcept : message(message)
{
#ifndef NDEBUG
2016-08-02 05:14:09 +08:00
this->message += '\n';
Stacktrace stacktrace;
for(auto& line : stacktrace)
2016-08-02 05:14:09 +08:00
this->message += fmt::format(" at {} ({})\n",
line.function, line.location);
#endif
}
2016-08-02 05:14:09 +08:00
template <class... Args>
BasicException(const std::string& format, Args&&... args) noexcept
: BasicException(fmt::format(format, std::forward<Args>(args)...)) {}
const char* what() const noexcept override
{
return message.c_str();
}
private:
std::string message;
};