Path: csiph.com!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Ian Collins Newsgroups: comp.lang.c++ Subject: Re: asserts considered harmful Date: Wed, 24 Feb 2016 14:55:21 +1300 Lines: 31 Message-ID: References: <8_2dnQWwaKOXRlHLnZ2dnUU7-dudnZ2d@giganews.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Trace: individual.net hrwl7Aaw0SYPt/9mjXH19wIpdof9Uz51Vn6P3Cl8VNnukvMGw7 Cancel-Lock: sha1:NnNDqRonW0skfw7bgzP4b7zC0/I= User-Agent: Mozilla/5.0 (X11; SunOS i86pc; rv:17.0) Gecko/17.0 Thunderbird/17.0 In-Reply-To: Xref: csiph.com comp.lang.c++:41212 Mr Flibble wrote: > On 24/02/2016 00:34, Ian Collins wrote: >> Mr Flibble wrote: >> If for an example an invalid pointer triggers an assert, I would want to >> know how this condition occurred, an assert and a core would give me the >> best chance of doing so. Even if the alternative exception captured the >> stack, it wouldn't help if the bad data came from another thread. >> >> Use exceptions where recovery is an option, asserts where it isn't. > > You are missing the point. If an incorrect index is being passed to > at() then it is likely that something is seriously amiss. But it shouldn't be a "this can never happen and if it does, we're screwed" condition where an assert is appropriate. >>> Following your logic to its ultimate conclusion there should exist a >>> proposal to deprecate/remove std::logic_error and exceptions derived >>> from it from C++. >> >> I think you lost the way somewhere. std::logic_error has its place, but >> that place isn't as a substitute for assert. > > Yes it is. Only if you control 100% of the code base and aren't too interested in fault finding the case of the throw. -- Ian Collins