Commit 4a162a93 authored by David Frank's avatar David Frank
Browse files

Add constructor to Error taking format string and arguments

Add a constructor taking a format string and arguments, which are passed
to fmt::format. This makes it quite convenient to pass arguments to
exceptions, i.e. `throw Error("value should be 0, but is {}", value);`.
parent 55c57239
......@@ -57,7 +57,7 @@ if(${ELSA_BUILD_WITH_QUICKVEC})
set(MODULE_SOURCES ${MODULE_SOURCES} Handlers/DataHandlerGPU.cpp Handlers/DataHandlerMapGPU.cpp)
endif()
list(APPEND MODULE_PUBLIC_DEPS "Eigen3::Eigen")
list(APPEND MODULE_PUBLIC_DEPS "Eigen3::Eigen" elsa_logging)
list(APPEND MODULE_PRIVATE_DEPS)
# use OpenMP if available
......@@ -142,4 +142,4 @@ if(ELSA_BUILD_PYTHON_BINDINGS)
)
endif()
write_module_config(${ELSA_MODULE_NAME})
write_module_config(${ELSA_MODULE_NAME} DEPENDENCIES elsa_logging)
......@@ -6,6 +6,8 @@
#include <string>
#include <sstream>
#include "spdlog/fmt/fmt.h"
namespace elsa
{
......@@ -29,6 +31,12 @@ namespace elsa
class Error : public std::runtime_error
{
public:
template <typename FormatString, typename... Args>
explicit Error(const FormatString& fmt, Args&&... args)
: Error(fmt::format(fmt, std::forward<Args>(args)...))
{
}
Error(std::string msg, bool generate_backtrace = true, bool store_cause = true);
~Error() override = default;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment