Skip to content

Supercharged C++ exceptions with support for source location and formatted strings

License

Notifications You must be signed in to change notification settings

lheer/superexceptions

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

superexceptions

What

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);

How

This is a header-only library. Simply include the file superexceptions.hpp to your project and compile/link against fmt.

About

Supercharged C++ exceptions with support for source location and formatted strings

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published