Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 06-27-2008, 03:11 PM
Member
 
Join Date: Jun 2008
Posts: 35
MarkWilson is on a distinguished road
try catch...
if i am having
1.try block with multiple catch statement , which one get executed
and how?
or
2.in try catch block can i have multiple finally block

try{
}
catch()
catch()
catch()
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 06-27-2008, 03:23 PM
Senior Member
 
Join Date: Jun 2008
Posts: 303
masijade is on a distinguished road
Well, considering these last three questions, I am going to stop giving you any advice/help/info, as it appears as though you are doing homework, or taking a quiz.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 06-27-2008, 03:30 PM
Member
 
Join Date: Jun 2008
Posts: 35
MarkWilson is on a distinguished road
no my dear friend ,i m not
c today is my 1st day in this forum
so the question i remember that question i m just asking

if u dont want to help me thn its ok ?
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 06-27-2008, 03:33 PM
Senior Member
 
Join Date: Jun 2008
Posts: 303
masijade is on a distinguished road
Then visit this site and work your way through it.

The Java™ Tutorials
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 06-27-2008, 03:37 PM
Member
 
Join Date: Jun 2008
Posts: 35
MarkWilson is on a distinguished road
but tell me the answer of my question in short .
thankx
Bookmark Post in Technorati
Reply With Quote
  #6 (permalink)  
Old 06-27-2008, 03:41 PM
Senior Member
 
Join Date: Jun 2008
Posts: 303
masijade is on a distinguished road
1 The first one that applies, of course.
2 Since a finally block is always executed, and is always executed last, what do you think?
Bookmark Post in Technorati
Reply With Quote
  #7 (permalink)  
Old 06-27-2008, 03:50 PM
Member
 
Join Date: Jun 2008
Posts: 35
MarkWilson is on a distinguished road
ok at first question i m asking
which catch stmt execute first , u say 1st one
but see if my code is
try
{
.... // database conn. logic
.
..}
catch(IOException e)
{
}
catch(SqlException e)
{
}
in this if i got some error during sql connectivity so catch(sqlException e) get call , am i right and wht abt 2nd one
this is my 1st Q?

now in 2. if i right system.exit(1) in try blk thn aslo my finally blk get executed . or some condition is there

plz reply
Bookmark Post in Technorati
Reply With Quote
  #8 (permalink)  
Old 06-27-2008, 03:54 PM
Senior Member
 
Join Date: Jun 2008
Posts: 303
masijade is on a distinguished road
Like I said, the first one that applies. Did you get an IOException or an SQLException?

Well, think of the finally block as a door, you have to open it before you can leave, however, if you burn the house down while your still in it, will you still be able the door? Of course if you terminate the program it won't execute, as the program execution will never come to that point, since it will already have burned to the ground.
Bookmark Post in Technorati
Reply With Quote
  #9 (permalink)  
Old 06-27-2008, 06:39 PM
Niveditha's Avatar
Senior Member
 
Join Date: May 2008
Posts: 299
Niveditha is on a distinguished road
Send a message via Skype™ to Niveditha
Hi,
I would like to answer your questions..
Quote:
1.try block with multiple catch statement , which one get executed
and how?
try
{
.... // database conn. logic
.
..}
catch(IOException e)
{
}
catch(SqlException e)
{
}
catch(Exception e)
{
}
When an exception is thrown it will check the 1st exception if the type doesnt match it will navigate to 2nd and so on untill it finds the correct type and if not found it will throw Exception and if it finds the correct type it wont check the other catch blocks.


You cant have a multiple finally block.There will be only one finally block for a try block.

Quote:
if i right system.exit(1) in try blk thn aslo my finally blk get executed
The answer for this would be NO. Finally block will get executed for everything even if the try block has a return stmt but if it has system.exit() finally block wont get executed as that stmt would cause jvm to shut down.
__________________
To finish sooner, take your own time....
Nivedithaaaa
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Error with my Try Catch kewlgeye New To Java 9 05-03-2008 04:38 AM
try catch!? Joe2003 Advanced Java 2 01-28-2008 08:51 PM
Try Catch Renegade85 New To Java 4 12-03-2007 05:10 PM
when to use try...catch javaplus New To Java 2 11-18-2007 09:52 PM
Use try and catch zoe New To Java 2 07-25-2007 08:50 PM


All times are GMT +3. The time now is 02:35 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org