From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!news.eternal-september.org!news.eternal-september.org!feeder.eternal-september.org!feeder.erje.net!eu.feeder.erje.net!nntp.club.cc.cmu.edu!micro-heart-of-gold.mit.edu!newsswitch.lcs.mit.edu!nntp.TheWorld.com!.POSTED!not-for-mail From: Robert A Duff Newsgroups: comp.lang.ada Subject: Re: OT: A bit of Sudoku Date: Thu, 05 Jun 2014 19:12:55 -0400 Organization: The World Public Access UNIX, Brookline, MA Message-ID: References: <5365d3f0-43cc-47ef-989c-d47992c84c9f@googlegroups.com> NNTP-Posting-Host: shell01.theworld.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: pcls7.std.com 1402009966 17194 192.74.137.71 (5 Jun 2014 23:12:46 GMT) X-Complaints-To: abuse@TheWorld.com NNTP-Posting-Date: Thu, 5 Jun 2014 23:12:46 +0000 (UTC) User-Agent: Gnus/5.1008 (Gnus v5.10.8) Emacs/21.3 (irix) Cancel-Lock: sha1:Cba9PKFTsbNMhd3UcY3S1RibxkU= Xref: news.eternal-september.org comp.lang.ada:20155 Date: 2014-06-05T19:12:55-04:00 List-Id: "J-P. Rosen" writes: > On the contrary, I think exception are perfectly appropriate for that: > they allow to unwind the call stack directly up to the point where you > want to catch it by providing a handler. I'm with J-P here. There are cases where exceptions can reasonably be used for not-so-exceptional cases. Maybe the OP's Sudoku solver is one such -- I haven't seen the code, so I don't know. > I know that not everybody likes this idea, ... That's somewhat of an understatement; many people are quite passionate about it, and say things like "Never use exceptions for control flow". But exceptions ARE control flow. When an exception is raised, a transfer of control to the handler happens (or to the end of the program if unhandled). It is impossible to use exceptions other than for control flow! Others add the word "normal": "Don't use exceptions for normal control flow". Unfortunately, it's unclear what "normal" means. >...but to me exceptions are a > powerful programming structure, not limited to handling errors. I agree. IMHO, the purpose of exceptions is to deal with the case where one piece of code detects an error (or maybe just an unusual situation), and a different piece of code knows what to do about it (or even to decide it's not an error after all). "end of file" might be considered an error by the file-reading procedure, but might be considered perfectly normal by the caller. So I don't think it makes sense to say "exceptions are ONLY for errors" -- different pieces of code have different views on whether it's an error. In any case, if you need to jump out of many layers of (recursive?) calls, an exception might well be the best way. Checking error codes at each level might be verbose and error prone. - Bob