Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!zen.net.uk!dedekind.zen.co.uk!reader02.nrc01.news.zen.net.uk.POSTED!not-for-mail From: Nobody Subject: Re: Error codes vs. exceptions Date: Wed, 30 May 2012 15:23:07 +0100 User-Agent: Pan/0.14.2 (This is not a psychotic episode. It's a cleansing moment of clarity.) Message-Id: Newsgroups: comp.programming,comp.lang.c++ References: <4f571f71-55ca-4922-b81b-31f954cac855@kw17g2000pbb.googlegroups.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Lines: 23 Organization: Zen Internet NNTP-Posting-Host: f0d9bac4.news.zen.co.uk X-Trace: DXC=6D I've heard about this, and wonder when is it right to use codes, and > when to use exceptions for reporting errors? I've heard various stuff, > such as that exceptions should only be used to indicate "exceptional" > conditions. Yet what does that mean? It usually means that the condition will rarely occur in practice. Performance-wise, exceptions are costly if the exception is actually thrown but free if not thrown, while a status return has a constant overhead. If the condition rarely occurs, exceptions will work out cheaper; if the condition is common, returning a status will be cheaper. But performance is seldom the main issue. If throwing an exception means that typical code will just wrap the call in a try/catch block, you should use a status return instead. If typical code will propagate errors up the call stack, you should probably use an exception. It's all about code structure. If exceptions make your code cleaner by reducing the amount of error-handling code, use exceptions. If they just mean that you replace if/else with try/catch, then use a status return.