Supercharged C++ exceptions with support for source location and formatted strings, leveraging fmt. Once you move to C++20, the external dependencies to fmt can be replaced by standard library headers. Requires C++17.
Instead of:
if (x > threshold)
{
throw std::runtime_error("Got " + std::to_string(x) + ", expected " + std::to_string(threshold));
}
write:
if (x > threshold)
{
throw lh::FormattedException("Got {}, expected {}", x, threshold);
}
Also supports embedding the source location from where the exception was thrown:
#include "source_location.hpp"
...
throw lh::LocatedException(nostd::source_location::current(), "Expection: {:#x}", 42);
This is a header-only library. Simply include the file superexceptions.hpp to your project and compile/link against fmt.