public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/103745] New: Warn on throwing an exception not derived from std::exception
@ 2021-12-16 8:56 antoshkka at gmail dot com
2021-12-16 9:05 ` [Bug c++/103745] " pinskia at gcc dot gnu.org
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: antoshkka at gmail dot com @ 2021-12-16 8:56 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103745
Bug ID: 103745
Summary: Warn on throwing an exception not derived from
std::exception
Product: gcc
Version: 12.0
Status: UNCONFIRMED
Keywords: diagnostic
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: antoshkka at gmail dot com
Target Milestone: ---
Throwing an exception that is derived from std::exception is a common practice.
Cases when that practice should be skipped are very rare. However, many
beginners do not know about that and erroneously do not derive their exceptions
from std::exception. There are also cases when classes have close names and
users throw the wrong type by a typo.
Please add a warning about throwing an exception not derived from
std::exception.
Godbolt playground: https://godbolt.org/z/7Phf3nafW
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug c++/103745] Warn on throwing an exception not derived from std::exception
2021-12-16 8:56 [Bug c++/103745] New: Warn on throwing an exception not derived from std::exception antoshkka at gmail dot com
@ 2021-12-16 9:05 ` pinskia at gcc dot gnu.org
2021-12-18 11:29 ` egallager at gcc dot gnu.org
2021-12-18 22:06 ` redi at gcc dot gnu.org
2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-12-16 9:05 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103745
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Severity|normal |enhancement
--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
> Throwing an exception that is derived from std::exception is a common practice.
Common practice where? in the standard library yes, outside of the wild not so
much.
I think this should be an optional warning which a project can turn on if they
want to or not.
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug c++/103745] Warn on throwing an exception not derived from std::exception
2021-12-16 8:56 [Bug c++/103745] New: Warn on throwing an exception not derived from std::exception antoshkka at gmail dot com
2021-12-16 9:05 ` [Bug c++/103745] " pinskia at gcc dot gnu.org
@ 2021-12-18 11:29 ` egallager at gcc dot gnu.org
2021-12-18 22:06 ` redi at gcc dot gnu.org
2 siblings, 0 replies; 4+ messages in thread
From: egallager at gcc dot gnu.org @ 2021-12-18 11:29 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103745
Eric Gallager <egallager at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |egallager at gcc dot gnu.org
--- Comment #2 from Eric Gallager <egallager at gcc dot gnu.org> ---
Could this go under the existing -Wexceptions flag?
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug c++/103745] Warn on throwing an exception not derived from std::exception
2021-12-16 8:56 [Bug c++/103745] New: Warn on throwing an exception not derived from std::exception antoshkka at gmail dot com
2021-12-16 9:05 ` [Bug c++/103745] " pinskia at gcc dot gnu.org
2021-12-18 11:29 ` egallager at gcc dot gnu.org
@ 2021-12-18 22:06 ` redi at gcc dot gnu.org
2 siblings, 0 replies; 4+ messages in thread
From: redi at gcc dot gnu.org @ 2021-12-18 22:06 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103745
--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> ---
I don't think so. What -Wexceptions warns about is almost always a bug (why
would you write a shadowed catch handler that can never catch anything?).
But the choice of whether to only throw things derived from std::exception or
not is purely stylistic, it's not about correctness. Users who want to know
about buggy catch handlers might not want warnings about a style issue they
don't agree with.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2021-12-18 22:06 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-16 8:56 [Bug c++/103745] New: Warn on throwing an exception not derived from std::exception antoshkka at gmail dot com
2021-12-16 9:05 ` [Bug c++/103745] " pinskia at gcc dot gnu.org
2021-12-18 11:29 ` egallager at gcc dot gnu.org
2021-12-18 22:06 ` redi at gcc dot gnu.org
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).