Article View: aus.computers.java
Article #201Re: throwing exceptions
From: Daniel Dyer
Date: Mon, 21 Apr 2003 19:45
Date: Mon, 21 Apr 2003 19:45
23 lines
1992 bytes
1992 bytes
On Mon, 21 Apr 2003 21:05:59 +0200, .Saphyr <saphyr@infomaniak.ch> wrote:
>> hal.openPodBayDoors();
>> try {
>> pod.enter();
>> }
>> catch (CannotEnterPodException e) {
>> hal.closePodBayDoors();
>> throw e;
>> }
>
>
> My question might sound basic but whats the point
> with the 'finally' statement ? Shouldn't it be used
> specifically for those cases ?
>
Yes, assuming you want the doors closed regardless of whether pod.enter()
succeeds, try...finally would be a better solution. However if your logic
is such that you require the doors to be closed only in an exceptional
circumstance, you would need to catch the exception and re-throw it.
Dan.
Technical Details
Message-ID:
<oprnzvtpfvm5rax9@localhost>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!newsfeed.icl.net!newsfeed.fjserv.net!diablo.theplanet.net!news.theplanet.net!not-for-mailReferences:
<puIna.11699$hF.92186@news-server.bigpond.net.au> <qDIna.110$KS4.52@news.get2net.dk> <ryTna.20910$y3.1898552@news010.worldonline.dk> <3EA0185D.C7B1A753@sun.com> <3ea44135$1_2@news.tiscalinet.ch>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10d6db,36528a6761383b70 X-Google-Attributes: gid10d6db,public X-Google-Thread: 113ae9,36528a6761383b70 X-Google-Attributes: gid113ae9,public X-Google-Thread: f5d71,36528a6761383b70 X-Google-Attributes: gidf5d71,public X-Google-ArrivalTime: 2003-04-21 12:44:28 PST Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!newsfeed.icl.net!newsfeed.fjserv.net!diablo.theplanet.net!news.theplanet.net!not-for-mail From: Daniel Dyer <dan@dontspamme.dover-athletic.co.uk> Newsgroups: aus.computers.java,comp.lang.java,comp.lang.java.help Subject: Re: throwing exceptions Date: Mon, 21 Apr 2003 20:45:15 +0100 Lines: 24 Message-ID: <oprnzvtpfvm5rax9@localhost> References: <puIna.11699$hF.92186@news-server.bigpond.net.au> <qDIna.110$KS4.52@news.get2net.dk> <ryTna.20910$y3.1898552@news010.worldonline.dk> <3EA0185D.C7B1A753@sun.com> <3ea44135$1_2@news.tiscalinet.ch> NNTP-Posting-Host: 81.78.75.62 Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed X-Trace: news8.svr.pol.co.uk 1050954268 20942 81.78.75.62 (21 Apr 2003 19:44:28 GMT) NNTP-Posting-Date: 21 Apr 2003 19:44:28 GMT X-Complaints-To: abuse@theplanet.net User-Agent: Opera7.10/Linux M2 build 388