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 04-09-2008, 09:23 AM
Member
 
Join Date: Apr 2008
Posts: 91
javarishi is on a distinguished road
Try---finally
Can Any One Suggest When We Need To Go For A Try-finally Instead Of Try-Catch-Finally
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 04-09-2008, 09:54 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 3,583
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
If you no need to catch exceptions, then use try-finally. try may be a block of code with multiple exit points. And the finally is another block of code that always executed when the try block is exit.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Has someone helped you? Then you can
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.

Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 04-09-2008, 09:58 AM
Member
 
Join Date: Apr 2008
Posts: 91
javarishi is on a distinguished road
Thanks Eranga. My Doubt Is If There Is No Need Of Handling Exception,

Why We Need To Put It In Try Block?. The CleanUp Code We Can Put

Inside finalize() block.?
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 04-09-2008, 10:01 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 3,583
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Yes, if you don't want to get the exceptions no need to add in a try block. But in some cases, such as working on an IDE, it automatically detect the exceptions and ask to include in try block.

Actually handling exceptions is really important. Are you try avoid those.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Has someone helped you? Then you can
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.

Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 04-09-2008, 10:05 AM
sanjeevtarar's Avatar
Senior Member
 
Join Date: Apr 2008
Location: Delhi(India)
Posts: 249
sanjeevtarar is on a distinguished road
and you will also need to put your code in Try block for Checked Exception, like IO,DateFormat etc.
Bookmark Post in Technorati
Reply With Quote
  #6 (permalink)  
Old 04-09-2008, 10:08 AM
Member
 
Join Date: Apr 2008
Posts: 91
javarishi is on a distinguished road
Eranga Sorry To Ask Again, But My Point Is Why We Need Some Code

Which Is Expected To Be Handled, Using Any Of The Exception Handling

Mechanism, ie try/catch, but need not be handled. If An Exception Is

Expected, then shouldn't it be handled?
Bookmark Post in Technorati
Reply With Quote
  #7 (permalink)  
Old 04-09-2008, 10:17 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 3,583
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
I'm not clear what you ask.

Are you looking another way to handle exceptions, rather than try/catch?
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Has someone helped you? Then you can
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.

Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #8 (permalink)  
Old 04-09-2008, 10:22 AM
Member
 
Join Date: Apr 2008
Posts: 91
javarishi is on a distinguished road
No. My Question Is Instead Of Try/Catch/finally When We Go For

Try/Finally We Are Not Handling The Exceptions, Right?.

So Here Is My Point. My Point Is That, If dont want to handle exception,

Why We need to go for try block?
Bookmark Post in Technorati
Reply With Quote
  #9 (permalink)  
Old 04-09-2008, 10:29 AM
sanjeevtarar's Avatar
Senior Member
 
Join Date: Apr 2008
Location: Delhi(India)
Posts: 249
sanjeevtarar is on a distinguished road
Ok do not use Try Block if you dont want handle Exceptions but you can not use finally block without Try.
Bookmark Post in Technorati
Reply With Quote
  #10 (permalink)  
Old 04-09-2008, 10:31 AM
Member
 
Join Date: Apr 2008
Posts: 91
javarishi is on a distinguished road
Sanjeev, then we can go for finalize() also to do the cleanup code right?
Bookmark Post in Technorati
Reply With Quote
  #11 (permalink)  
Old 04-09-2008, 10:42 AM
sanjeevtarar's Avatar
Senior Member
 
Join Date: Apr 2008
Location: Delhi(India)
Posts: 249
sanjeevtarar is on a distinguished road
Yes you are right,
finally block is only for cleanup with try block.


sanjeev
Bookmark Post in Technorati
Reply With Quote
  #12 (permalink)  
Old 04-09-2008, 10:58 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 3,583
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
That's what I have explained in my first post pal. Don't you clear that?
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Has someone helped you? Then you can
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.

Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #13 (permalink)  
Old 04-09-2008, 10:59 AM
Member
 
Join Date: Apr 2008
Posts: 91
javarishi is on a distinguished road
Thanks Eranga. I will explore more on this, and will come back. Thank you very much
Bookmark Post in Technorati
Reply With Quote
  #14 (permalink)  
Old 04-09-2008, 11:07 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 3,583
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Sure, anytime. And also you can throws exceptions if you want. In that case you no need to worried about try/catch also.

As you said explorer something by yourself. You may come across with something interesting.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Has someone helped you? Then you can
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.

Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #15 (permalink)  
Old 04-09-2008, 11:34 AM
Member
 
Join Date: Apr 2008
Posts: 91
javarishi is on a distinguished road
Sure, Eranga
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



All times are GMT +3. The time now is 07:41 PM.


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