comp.lang.ada
 help / color / mirror / Atom feed
From: Robert A Duff <bobduff@shell01.TheWorld.com>
Subject: Re: OT: A bit  of Sudoku
Date: Thu, 05 Jun 2014 19:12:55 -0400
Date: 2014-06-05T19:12:55-04:00	[thread overview]
Message-ID: <wccbnu73q88.fsf@shell01.TheWorld.com> (raw)
In-Reply-To: lmqeoe$o76$1@dont-email.me

"J-P. Rosen" <rosen@adalog.fr> 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

  parent reply	other threads:[~2014-06-05 23:12 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-06-05 17:49 OT: A bit of Sudoku Mike H
2014-06-05 18:30 ` Adam Beneschan
2014-06-05 19:00   ` J-P. Rosen
2014-06-05 19:18     ` Jeffrey Carter
2014-06-05 19:43       ` J-P. Rosen
2014-06-05 20:05     ` Mike H
2014-06-05 23:12     ` Robert A Duff [this message]
2014-06-05 23:39       ` Adam Beneschan
2014-06-06  7:51         ` Dmitry A. Kazakov
2014-06-06  9:21           ` Georg Bauhaus
2014-06-06 13:38             ` Dmitry A. Kazakov
2014-06-06 15:47           ` Adam Beneschan
2014-06-06 17:09             ` Dmitry A. Kazakov
2014-06-07  6:03             ` J-P. Rosen
2014-06-06 14:13         ` Brad Moore
2014-06-13  0:21     ` Shark8
2014-06-13  6:30       ` J-P. Rosen
2014-06-13 10:10       ` Mike H
2014-06-13 12:37         ` Dmitry A. Kazakov
2014-06-13 15:47         ` Shark8
2014-06-05 20:03   ` Mike H
2014-06-05 20:40     ` Adam Beneschan
2014-06-06  9:10       ` Stefan.Lucks
2014-06-06 10:59         ` Mike H
2014-06-06 16:06         ` Adam Beneschan
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox