Skip to content

Exception formatting is undocumented #4203

Description

@robinchrist

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions