-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add formatter for std::exception #3062
Conversation
Will come back and fix those failing CI jobs in a couple of days 👍 |
1cc09bc
to
7da2a28
Compare
b5c02fc
to
2821d2c
Compare
Co-authored-by: fekir <federico.kircheis@gmail.com> Co-authored-by: Alexey Ochapov <alexez@alexez.com> Co-authored-by: Vladislav Shchapov <vladislav@shchapov.ru>
2821d2c
to
76adb05
Compare
Sorry for a stupid, uneducated question. E.g. a std::runtime_error("My exception") would then be formatted as "std::runtime_error: My exception", as it typically is formatted in C#, by using typeid(xxx).name()? |
Not necessarily previously discussed (@vitaut's suggestions in #3012 (comment)), but you're right in that it isn't super portable to do that: Using: return fmt::formatter<string_view>::format(fmt::format("{}: {}", typeid(T).name(), ex.what()), ctx); clang (name mangling):
MSVC (addition of "class"):
|
For gcc you can demangle the name, and for msvc you can strip the class I guess. Not sure about clang. Searching online, it generally seems like a doable thing, at least for the 3 main compilers, although it would introduce a lot of complexity that might not not be wanted in fmtlib. |
Thank you! |
Adds a single simple formatter for
std::exception
and accompanying test.Reference:
#2977
#3012
Closes #2977