comp.lang.ada
 help / color / mirror / Atom feed
From: Darren New <dnew@san.rr.com>
Subject: Re: Ada exceptions. unchecked?
Date: Wed, 12 Jun 2002 16:07:20 GMT
Date: 2002-06-12T16:07:20+00:00	[thread overview]
Message-ID: <3D0771D3.FFEA1AA4@san.rr.com> (raw)
In-Reply-To: $4ctS45vG2pB@eisner.encompasserve.org

Larry Kilgallen wrote:
> But what about all those exceptions like Program Error that might be
> signalled other than by the explicit choice of the programmer ?  Are
> there two classes of exceptions ?

Yes. Checked and Unchecked. :-) And the programmer is allowed to declare
unchecked exceptions. (And I think they're actually called something like
Exception and RunTimeException or some such.)

In my experience, the vast majority of Java code winds up catching all the
checked exceptions and turning them into unchecked exceptions before
rethrowing them. This is because there are a lot of callbacks declared not
to throw exceptions, and a lot of library routines that do throw exceptions.

For a sloppy and imprecise example,
  application's main calls file_open_dialog,
    file_open_dialog calls gui_button_handler
      gui_button_handler calls application's load_file
        application's load_file calls Java's read, which throws EOF_error.

At this point, the application's load_file has to get the error back to the
application's main routine to be handled. But the gui_button_handler doesn't
declare that it can throw EOF_error, because the button hasn't anything to
do with files. So the normal technique is to create a new unchecked
exception and pass the checked exception in the constructor, then throw
that, then catch it in the main routine and unwrap it.

That is to say, one tends to do the same thing with checked exceptions in
Java as one does with collections: cast everything to the same type, then
recast it to the type you expect later. I've found the checking really
doesn't help much at all, except to those C programmers who when reading a
file assume you never hit the end of file early, and who assume a file is
never deleted between the time you take a listing of the directory and the
time you try to open a file, and etc.

-- 
Darren New 
San Diego, CA, USA (PST). Cryptokeys on demand.
** http://home.san.rr.com/dnew/DNResume.html **
** http://images.fbrtech.com/dnew/ **

     My brain needs a "back" button so I can
         remember where I left my coffee mug.



  reply	other threads:[~2002-06-12 16:07 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-06-12  7:00 Ada exceptions. unchecked? steve_H
2002-06-12 13:52 ` Ted Dennison
2002-06-12 14:09 ` Larry Kilgallen
2002-06-12 13:47   ` Mark Johnson
2002-06-12 15:40     ` Larry Kilgallen
2002-06-12 16:07       ` Darren New [this message]
2002-06-12 22:21         ` Dale Stanbrough
2002-06-13 14:36           ` Hyman Rosen
2002-06-13 16:41             ` Darren New
2002-06-13 17:13               ` Hyman Rosen
2002-06-13 17:48                 ` Darren New
2002-06-13 18:06                   ` Hyman Rosen
2002-06-13 18:37                     ` Darren New
2002-06-13 19:14                       ` Hyman Rosen
2002-07-05 14:35                         ` Stephen J. Bevan
2002-06-12 19:25     ` Simon Wright
2002-06-12 22:19     ` Gisle Sælensminde
2002-06-13 14:27       ` Mark Johnson
2002-06-14 21:32         ` Gisle Sælensminde
2002-06-14 21:45           ` Darren New
2002-06-15 15:10           ` Simon Wright
2002-06-15 21:26             ` AG
2002-06-15 23:37               ` Darren New
2002-06-15 23:50                 ` AG
2002-06-15 23:57                   ` Darren New
2002-06-17 18:21             ` Charles Lindsey
2002-06-18 16:32             ` Stephen Leake
2002-06-18 19:48               ` Wes Groleau
replies disabled

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