comp.lang.ada
 help / color / mirror / Atom feed
From: Jeffrey Carter <jrcarter@acm.org>
Subject: Re: Good Ada Style For Impossible Actions?
Date: Sat, 26 Oct 2002 21:11:07 GMT
Date: 2002-10-26T21:11:07+00:00	[thread overview]
Message-ID: <3DBB0508.6010707@acm.org> (raw)
In-Reply-To: VZyu9.20022$T_.482707@iad-read.news.verio.net

Dr Nancy's Sweetie wrote:
> Considering the parallel with reading input, I could write two functions,
> a "Display.Within_Active_Window", returning a Boolean, and then put the
> call to Display.Translate_Mouse_Event inside an "if" (following the example
> of Ada's "End_Of_File" function, which you call before calling "Get",
> instead of calling Get and seeing if it returns a special value).
> 
> Then I realised that this could also be done with an exception: I could
> make up an exception, "Not_In_Active_Window", have Translate_Mouse_Event
> raise that exception if the Mouse_Event wasn't in the window, and then
> just have a little begin..exception..end block in the code.
> 
> But of these last two approaches, I don't have a feeling for which one is
> Good Ada Style(tm).  Should exceptions only be used for serious problems?
> Using it here would remove a function and chop out some lines of code, but
> it's not really much of a savings and the exception block feels like it
> would clutter up the event loop at least as much as the if-then.

Exceptions should be reserved for exceptional situations. Reading past 
the end of a file is exceptional because you're expected to test to see 
if you're at the end of the file before reading. If you then read past 
the end of file anyway, something exceptional has happened.

It sounds as if you could have mouse events outside the proper window at 
any time, so such an event would not be exceptional. So having a 
function would probably be a good idea.

But if you use the function and still get a mouse event outside the 
proper window, you should also have an exception to indicate that.

-- 
Jeff Carter
"All citizens will be required to change their underwear
every half hour. Underwear will be worn on the outside,
so we can check."
Bananas




  reply	other threads:[~2002-10-26 21:11 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-10-26 15:59 Good Ada Style For Impossible Actions? Dr Nancy's Sweetie
2002-10-26 21:11 ` Jeffrey Carter [this message]
2002-10-28  3:52   ` Dr Nancy's Sweetie
2002-10-28 17:13     ` Jeffrey Carter
2002-10-28 17:33       ` tmoran
2002-10-29  1:35         ` Dr Nancy's Sweetie
2002-10-28 17:52       ` Warren W. Gay VE3WWG
replies disabled

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