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 13:25:55 +1300 Lines: 18 Message-ID: References: <8_2dnQWwaKOXRlHLnZ2dnUU7-dudnZ2d@giganews.com> <6a6dndcqc5TVdFHLnZ2dnUU7-eednZ2d@giganews.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Trace: individual.net wfv4p1tKPWzjj4mM//W6IQ+19fOzf/A527SS7wqcPOKx5F7dDN Cancel-Lock: sha1:rge0byZLvVQRgC8v963HZyiQPvw= 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++:41207 Mr Flibble wrote: > > std::logic_error exceptions can be caught, logged and re-thrown > (terminating application) which is the only acceptable course of action: > logic errors are non-recoverable; if one has been detected something is > seriously amiss and to try to carry on regardless would be extremely > unwise. Education is necessary to ensure this is done by the coder: > just because some people might be handling it incorrectly doesn't mean > it is unsound advice to follow especially for new non-legacy code. Unless you control all of the code, how can you grantee that there isn't a catch or std::exception somewhere in the call frame between your throw and catch of std::logic_error? If (and that is a big if) you are going to use an exception rather than an assert, it should be something outside of the standard exception hierarchy. -- Ian Collins