memgraph/include/utils/exceptions/basic_exception.hpp
Kruno Tomola Fabro 5d235b51f3 tmp commit
tmp commit

tmp commit v2

Finished reimplementation of propertys.
They now can be placed in a holder with different source of type information.

Tmp commit
2016-09-05 10:02:48 +01:00

45 lines
1.1 KiB
C++

#pragma once
#include <fmt/format.h>
#include <stdexcept>
#include "utils/auto_scope.hpp"
#include "utils/stacktrace.hpp"
class BasicException : public std::exception
{
public:
BasicException(const std::string &message) noexcept : message(message),
stacktrace_size(10)
{
#ifndef NDEBUG
this->message += '\n';
Stacktrace stacktrace;
// TODO: write this better
// (limit the size of stacktrace)
uint64_t count = 0;
for (auto &line : stacktrace) {
this->message +=
fmt::format(" at {} ({})\n", line.function, line.location);
if (++count >= stacktrace_size) break;
}
#endif
}
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;
uint64_t stacktrace_size;
};