Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.programming > #1678
| From | Nobody <nobody@nowhere.com> |
|---|---|
| Subject | Re: Error codes vs. exceptions |
| Date | 2012-05-31 05:04 +0100 |
| Message-Id | <pan.2012.05.31.04.04.35.489000@nowhere.com> |
| Newsgroups | comp.programming, comp.lang.c++ |
| References | <4f571f71-55ca-4922-b81b-31f954cac855@kw17g2000pbb.googlegroups.com> <4fc6db28$0$561$c3e8da3$4db35a27@news.astraweb.com> |
| Organization | Zen Internet |
Cross-posted to 2 groups.
On Wed, 30 May 2012 22:44:56 -0400, Pavel wrote: > I know you have already received lots of advice; but I think they omit an > important factor, namely whether you are writing a library. In my > experience, I found it quite annoying when the API of a library I use can > throw. Catching all possible exceptions after every call is even more > disrupting than processing return codes and letting them through often > creates a mess with multiple error processing policies coming from > different libraries or from my application and library or libraries it > uses. That's a non-issue for exceptions which should never need to be thrown in the first place, e.g. an invalid argument value. If you don't want to have to catch such exceptions, don't cause them to be thrown. Even where it is an issue, any API design involves trade-offs. Having every function return a status indication may be more efficient for code which always handles failures directly in the caller. OTOH, it imposes a significant burden on code which would otherwise just allow an exception to propagate up to a higher level. It's impossible to provide a hard-and-fast definition of which conditions are "exceptional", particularly for a library. OTOH, it's equally impossible to provide a hard-and-fast rule regarding the side on which to err. Treating any condition which might conceivably be caught in the immediate caller as non-exceptional is likely to result in a rather inconvenient API for the majority of code. I mean, the STL *could* have a given every container type a "bad bit" (in the same vein as iostream) to indicate allocation failure, but I'm rather glad it didn't.
Back to comp.programming | Previous | Next — Previous in thread | Next in thread | Find similar
Error codes vs. exceptions mike3 <mike4ty4@yahoo.com> - 2012-05-28 21:15 -0700
Re: Error codes vs. exceptions BGB <cr88192@hotmail.com> - 2012-05-29 00:10 -0500
Re: Error codes vs. exceptions mike3 <mike4ty4@yahoo.com> - 2012-05-28 22:41 -0700
Re: Error codes vs. exceptions BGB <cr88192@hotmail.com> - 2012-05-29 01:34 -0500
Re: Error codes vs. exceptions Adam Skutt <askutt@gmail.com> - 2012-05-29 07:16 -0700
Re: Error codes vs. exceptions BGB <cr88192@hotmail.com> - 2012-05-29 09:45 -0500
Re: Error codes vs. exceptions Marcel Müller <news.5.maazl@spamgourmet.com> - 2012-05-29 09:08 +0200
Re: Error codes vs. exceptions mike3 <mike4ty4@yahoo.com> - 2012-05-31 13:52 -0700
Re: Error codes vs. exceptions Ian Collins <ian-news@hotmail.com> - 2012-06-01 09:08 +1200
Re: Error codes vs. exceptions mike3 <mike4ty4@yahoo.com> - 2012-05-31 22:32 -0700
Re: Error codes vs. exceptions "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> - 2012-05-29 09:37 +0200
Re: Error codes vs. exceptions "io_x" <a@b.c.invalid> - 2012-05-29 10:00 +0200
Re: Error codes vs. exceptions Jorgen Grahn <grahn+nntp@snipabacken.se> - 2012-05-29 12:24 +0000
Re: Error codes vs. exceptions Nobody <nobody@nowhere.com> - 2012-05-30 15:23 +0100
Re: Error codes vs. exceptions BGB <cr88192@hotmail.com> - 2012-05-30 09:40 -0500
Re: Error codes vs. exceptions Adam Skutt <askutt@gmail.com> - 2012-05-30 08:04 -0700
Re: Error codes vs. exceptions BGB <cr88192@hotmail.com> - 2012-05-30 12:01 -0500
Re: Error codes vs. exceptions Jeff Flinn <TriumphSprint2000@hotmail.com> - 2012-05-30 14:18 -0400
Re: Error codes vs. exceptions Patricia Shanahan <pats@acm.org> - 2012-05-30 13:00 -0700
Re: Error codes vs. exceptions Adam Skutt <askutt@gmail.com> - 2012-05-30 21:25 -0700
Re: Error codes vs. exceptions Pavel <pauldontspamtolk@removeyourself.dontspam.yahoo> - 2012-05-30 22:44 -0400
Re: Error codes vs. exceptions Nobody <nobody@nowhere.com> - 2012-05-31 05:04 +0100
Re: Error codes vs. exceptions Pavel <pauldontspamtolk@removeyourself.dontspam.yahoo> - 2012-06-01 21:44 -0400
Re: Error codes vs. exceptions "Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com> - 2012-06-02 08:39 +0200
Re: Error codes vs. exceptions BGB <cr88192@hotmail.com> - 2012-06-02 16:31 -0500
Re: Error codes vs. exceptions mike3 <mike4ty4@yahoo.com> - 2012-06-02 15:49 -0700
Re: Error codes vs. exceptions Ian Collins <ian-news@hotmail.com> - 2012-06-03 11:17 +1200
Re: Error codes vs. exceptions Rui Maciel <rui.maciel@gmail.com> - 2012-06-03 16:38 +0100
Re: Error codes vs. exceptions Pavel <pauldontspamtolk@removeyourself.dontspam.yahoo> - 2012-06-03 20:26 -0400
Re: Error codes vs. exceptions gremnebulin <peterdjones@yahoo.com> - 2012-06-20 12:05 -0700
csiph-web