[Bug libstdc++/78710] suggest better exception text for stoi, stol, ...

2023-07-13 Thread redi at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78710

Jonathan Wakely  changed:

   What|Removed |Added

   Assignee|unassigned at gcc dot gnu.org  |redi at gcc dot gnu.org
 Status|NEW |ASSIGNED

[Bug libstdc++/78710] suggest better exception text for stoi, stol, ...

2021-03-08 Thread redi at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78710

--- Comment #2 from Jonathan Wakely  ---
(In reply to Nicolai Josuttis from comment #0)
> stoi("hello") currently throws an exception where what() only outputs "stoi"
> (nothing else).

The type of the exception is significant too. It can either throw
std::invalid_argument("stoi") or std::out_of_range("stoi").


> Some component (either __stoa() or __throw_invalid_argument())
> should extend the message at least a bit.
> E.g. __stoa() might call
>std::__throw_invalid_argument("invalid argument for " + __name)

This makes it (very slightly) more likely to throw std::bad_alloc than to throw
what we actually want to throw. It's probably a reasonable trade-off to get a
better what() message though.

[Bug libstdc++/78710] suggest better exception text for stoi, stol, ...

2021-03-08 Thread redi at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78710

Jonathan Wakely  changed:

   What|Removed |Added

 Ever confirmed|0   |1
   Last reconfirmed||2021-03-08
 Status|UNCONFIRMED |NEW
  Component|c++ |libstdc++