Newsgroups: comp.lang.c++.moderated
From: James Kanze <James.Ka...@dresdner-bank.com>
Date: 12 Dec 2000 07:47:51 -0500
Local: Tues, Dec 12 2000 7:47 am
Subject: Re: consensus on exceptions?
Gabriel Zachmann wrote: There is no concensus. Some people swear by them. Others swear at > I am trying to decide whether or not to use exceptions. > I searched this NG with deja > and read some GotW (http://www.peerdirect.com/resources/) > and some C++ tips (http://cpptips.hyperformix.com/Exceptions.html); > in particular http://cpptips.hyperformix.com/cpptips/except_consensus > was very informative. > But I'm afraid I still don't see if there is a consensus > whether or not > Exceptions are a Good Thing? them. > I found a lot of tips and discussion about the technicalities of Add overloaded operators to 3, and you've summarized it pretty well. > exceptions, but the big question is > From what I read, there seems to be a consensus that: > 1. Writing exception-safe code is harder than without exceptions; > 2. Excpetions introduce a second path of control flow "behind the scenes", > which increases the complexity of the code; > 3. In order to do decent error-handling in constructors, you must use > exceptions. On the other hand, it's possible to design constructors so they don't fail, or so that you can check them afterwards (a la iostream), so it's not necessarily as big a point as is sometimes pretended. And you missed: 4. Exceptions make the main body of the function simpler, so easier to I don't think there is one true answer. Generally, I'm fairly Globally, I'd say that exceptions should not be used in a critical > So, my questions are: No. Be consistent. > a) should I use exceptions only for constructors and error codes for > all other methods? > b) if exceptions are used in general, should functions return *only* Ditto. > error codes *or* throw exceptions? (i.e., is it ok to mix both in one > method?) > c) should exceptions be used only for "exceptional" cases, or could they I would hope that a bogus parameter is something really exceptional, > also be used for not-so-exceptional things, like bogus parameters passed > in from the caller? if it comes from within my program. I wouldn't use exceptions for errors in user input, however. -- [ Send an empty e-mail to c++-h...@netlab.cs.rpi.edu for info ] You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
| ||||||||||||||