Skip to content

Support std::exception #2977

Description

@fekir

Exceptions are not supported, as they are not formattable:

int main() try {
  std::vector <int> vec;
  vec.at(42);
} catch(const std::out_of_range& ex){
    fmt::print("{}", ex);
}

https://godbolt.org/z/ejTMEYr3b

In practice, the expected/desired behavior would be to print the error message.
Ie if they would behave as-if

int main() try {
  std::vector<int> vec;
  vec.at(42);
} catch(const std::out_of_range& ex){
  fmt::print("{}", ex.what());
}

This can be accomplished by defining a custom formatter for std::exception, but as fmt already provides formatters for many/most types from the standard library, support for std::exception should be part of it.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions