C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Formatting std::exception?

From: Jens Maurer <jens.maurer_at_[hidden]>
Date: Fri, 12 Dec 2025 09:23:53 +0100
On 12/12/25 04:46, 叶易安 via Std-Proposals wrote:
> Most times we would like to know as more message as possible when an error occurs, such as:
> 1. which argument is invalid
> 2. stacktrace [available by std::set_terminate(std::stacktrace::current()...)]
>
> Currently the message in [1.] is always useless. For example:
> (clang22): "libc++abi: terminating due to uncaught exception of type std::out_of_range: vector"
>
> Gcc15 saw this problem, and has internally changed the `std::vector::at()` implementation by calling a new `__throw_out_of_range_fmt`. Now gcc can provide a much helpful output:
> (gcc15): "what(): vector::_M_range_check: __n (which is 42) >= this->size() (which is 24)"

I'm pretty sure that helper function won't go away,
because exceptions are (supposed to be) rare and you
don't want inline code generation for the exception setup.

Jens

Received on 2025-12-12 08:23:57