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=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,98c463a9e98cfdf5 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2002-06-12 09:07:24 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!newsfeed1.cidera.com!Cidera!cyclone.socal.rr.com!cyclone3.kc.rr.com!news3.kc.rr.com!twister.socal.rr.com.POSTED!not-for-mail Message-ID: <3D0771D3.FFEA1AA4@san.rr.com> From: Darren New X-Mailer: Mozilla 4.77 [en] (Windows NT 5.0; U) X-Accept-Language: en MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Ada exceptions. unchecked? References: <8db3d6c8.0206112300.3965a62b@posting.google.com> <3D0750F1.7A12342@raytheon.com> <$4ctS45vG2pB@eisner.encompasserve.org> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Date: Wed, 12 Jun 2002 16:07:20 GMT NNTP-Posting-Host: 66.75.151.160 X-Complaints-To: abuse@rr.com X-Trace: twister.socal.rr.com 1023898040 66.75.151.160 (Wed, 12 Jun 2002 09:07:20 PDT) NNTP-Posting-Date: Wed, 12 Jun 2002 09:07:20 PDT Organization: RoadRunner - West Xref: archiver1.google.com comp.lang.ada:25802 Date: 2002-06-12T16:07:20+00:00 List-Id: 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.