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

Support std::exception #2977

Closed
fekir opened this issue Jul 7, 2022 · 1 comment · Fixed by #3062
Closed

Support std::exception #2977

fekir opened this issue Jul 7, 2022 · 1 comment · Fixed by #3062

Comments

@fekir
Copy link
Contributor

fekir commented Jul 7, 2022

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.

@vitaut
Copy link
Contributor

vitaut commented Jul 11, 2022

Sure, a PR to add a formatter specialization is welcome.

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

Successfully merging a pull request may close this issue.

2 participants