Skip to content
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

Exception formatting is undocumented #4203

Closed
robinchrist opened this issue Oct 16, 2024 · 1 comment
Closed

Exception formatting is undocumented #4203

robinchrist opened this issue Oct 16, 2024 · 1 comment

Comments

@robinchrist
Copy link

robinchrist commented Oct 16, 2024

Formatting for exceptions exists (e.g. via #3062 or #3076).
This is not documented (missing in the list at

fmt/doc/api.md

Lines 491 to 505 in cc2ba8f

<a id="std-api"></a>
## Standard Library Types Formatting
`fmt/std.h` provides formatters for:
- [`std::atomic`](https://en.cppreference.com/w/cpp/atomic/atomic)
- [`std::atomic_flag`](https://en.cppreference.com/w/cpp/atomic/atomic_flag)
- [`std::bitset`](https://en.cppreference.com/w/cpp/utility/bitset)
- [`std::error_code`](https://en.cppreference.com/w/cpp/error/error_code)
- [`std::filesystem::path`](https://en.cppreference.com/w/cpp/filesystem/path)
- [`std::monostate`](https://en.cppreference.com/w/cpp/utility/variant/monostate)
- [`std::optional`](https://en.cppreference.com/w/cpp/utility/optional)
- [`std::source_location`](https://en.cppreference.com/w/cpp/utility/source_location)
- [`std::thread::id`](https://en.cppreference.com/w/cpp/thread/thread/id)
- [`std::variant`](https://en.cppreference.com/w/cpp/utility/variant/variant)
).

Additionally, there seem to be different ways to format exceptions (without any specified and with {:t}), as can be seen from the tests:

fmt/test/std-test.cc

Lines 311 to 318 in cc2ba8f

try {
using namespace my_ns1::my_ns2;
throw my_exception("My Exception");
} catch (const std::exception& ex) {
EXPECT_EQ("my_ns1::my_ns2::my_exception: My Exception",
fmt::format("{:t}", ex));
EXPECT_EQ("My Exception", fmt::format("{:}", ex));
}

This is undocumented in https://github.com/fmtlib/fmt/blob/cc2ba8f9ede4e5ae3262f43f3e4d07a22a9acdfc/doc/syntax.md. The only reference in the docs to t is A horizontal-tab character. for chrono

@vitaut
Copy link
Contributor

vitaut commented Oct 20, 2024

Formatting of std::exception is still WIP/experimental and exact format string syntax is subject to change but I added it to the list in https://fmt.dev/dev/api/#standard-library-types-formatting.

@vitaut vitaut closed this as completed Oct 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants