Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Ian Collins Newsgroups: comp.programming,comp.lang.c++ Subject: Re: Error codes vs. exceptions Date: Fri, 01 Jun 2012 09:08:21 +1200 Lines: 31 Message-ID: References: <4f571f71-55ca-4922-b81b-31f954cac855@kw17g2000pbb.googlegroups.com> <4fc4760a$0$6567$9b4e6d93@newsspool4.arcor-online.net> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit X-Trace: individual.net if5kAKagZFXS8MK9aDyYCAH3dUGymfXzT7jiruAzgkU5CCYFjTZpIT9id2e9Jd4weV Cancel-Lock: sha1:nf9w3FCI0DaD1NVif/CQ2GdOvns= User-Agent: Mozilla/5.0 (X11; SunOS i86pc; rv:12.0) Gecko/20120423 Thunderbird/12.0 In-Reply-To: Xref: csiph.com comp.programming:1690 comp.lang.c++:16470 On 06/ 1/12 08:52 AM, mike3 wrote: > On May 29, 1:08 am, Marcel Müller > wrote: > >>> Would that be OK or excessive use of exceptions? And if we >>> are to mix error codes and exceptions, does this mean we should have >>> the lists of codes and exceptions correspond + a translator to >>> translate between the two? >> >> Converting an error code into an exception might be a good idea. But the >> other way around is most likely not. >> >> And another rule of thumb: the number of exceptions thrown during the >> processing of a complete request should be finite. I.e. it must not >> scale with the amount of data processed. >> >> Marcel > > So does this mean we should have an exception class defined for every > error code, so we can do that "conversion"? That really depends what you intend to do when you catch one. I tend to use an exception type for a family of error codes and include the actual code in there. Most of my simple applications just catch the base exception (std::runtime_error), send the result of what() to cerr and exit. If the application can recover from a specific type of exception, I'll catch those a perform whatever recovery or reporting is required. -- Ian Collins