Article View: borland.public.jbuilder.java.language
Article #16Re: try{}catch{}finally{} bloks
From: Randy Spitz
Date: Fri, 02 Oct 1998 00:00
Date: Fri, 02 Oct 1998 00:00
83 lines
3535 bytes
3535 bytes
Vladimir,
Use a finally branch for code that you want to execute if an exception occured OR NOT. The catch branch is for code that should only
execute if an exception occurs.
-Randy Spitz
DeVries Data Systems, Inc.
Vladimir Olenin wrote:
> Well, the problem is that in the following fragment of program statement
> after catch and finally blocks is unreachable. When i just quote finally
> block out, evrth compiles fine. Just that human curiosity... It seems
> like finally block executes anyway no matter was there an exception or
> not. As i know it should be executed only if an exception occurred. So,
> am i right or wrong?
>
> public void run(){
> String inMessage[] = new String[2];
> try{
> while(true){
> try{
> inMessage = (String[])in.readObject();
> }
> catch(IOException eIO){
> inMessage[0] = "Server";
> inMessage[1] = "I/O error occured while message receiving. U
> are to be disconnected";
> // processConnectionEvent(
> // new ConnectionEvent(this, inMessage,
> ConnectionEvent.EXCEPTION));
> // throw new Exception();
> }
> catch(ClassNotFoundException eCNF){
> inMessage[0] = "Server";
> inMessage[1] = "Serialization error occured while message
> receiving. U are to be disconnected";
> // processConnectionEvent(
> // new ConnectionEvent(this, inMessage,
> ConnectionEvent.EXCEPTION));
> // throw new Exception();
> }
> catch(NullPointerException NPe){
> inMessage[0] = "Server";
> inMessage[1] = "Null object has been received. U are to be
> disconnected";
> // processConnectionEvent(
> // new ConnectionEvent(this, inMessage,
> ConnectionEvent.EXCEPTION));
> // throw new Exception();
> }
>
> finally{
> processConnectionEvent(
> new ConnectionEvent(this, inMessage,
> ConnectionEvent.EXCEPTION));
> throw new Exception();
> }
>
> processConnectionEvent(
> new ConnectionEvent(this, inMessage,
> parseMessage(inMessage)));
> }
> }
> catch(Exception e){
> closeConnection();
> this.stop();
> }
> }
>
> ------------------------------------------------------------------------
>
> <keenonjava@collegemail.com>
> version:2.1
> Java programmer. Open for project development offers. See my home page at: http://www.geocities.com/SiliconValley/Heights/9815/
> Additional Information:
> Last Name Vladimir
> First Name Olenin
> Version 2.1
--
-----------------------------------------------
Remove "NOSPAM." in EMail address when replying
Technical Details
Message-ID:
<36157492.B56C6F49@gte.net>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<361559E1.9DB2FC20@collegemail.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: ff01d,514609b11f439a4,start
X-Google-Attributes: gidff01d,public
X-Google-Thread: f74b3,514609b11f439a4,start
X-Google-Attributes: gidf74b3,public
From: Randy Spitz <rspitz@gte.net>
Subject: Re: try{}catch{}finally{} bloks
Date: 1998/10/02
Message-ID: <36157492.B56C6F49@gte.net>
X-Deja-AN: 397224671
Content-Transfer-Encoding: 7bit
References: <361559E1.9DB2FC20@collegemail.com>
Content-Type: text/plain; charset=us-ascii
Organization: Another Netscape Collabra Server User
Mime-Version: 1.0
Reply-To: rspitz@NOSPAM.gte.net
Newsgroups: borland.public.jbuilder.java.language,borland.public.jbuilder.applet-issues