|
|
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.
|
|

04-09-2008, 09:23 AM
|
|
Member
|
|
Join Date: Apr 2008
Posts: 91
|
|
|
Try---finally
Can Any One Suggest When We Need To Go For A Try-finally Instead Of Try-Catch-Finally
|
|

04-09-2008, 09:54 AM
|
 |
Moderator
|
|
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 3,583
|
|
|
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.
|
|

04-09-2008, 09:58 AM
|
|
Member
|
|
Join Date: Apr 2008
Posts: 91
|
|
|
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.?
|
|

04-09-2008, 10:01 AM
|
 |
Moderator
|
|
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 3,583
|
|
|
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.
|
|

04-09-2008, 10:05 AM
|
 |
Senior Member
|
|
Join Date: Apr 2008
Location: Delhi(India)
Posts: 249
|
|
|
and you will also need to put your code in Try block for Checked Exception, like IO,DateFormat etc.
|
|

04-09-2008, 10:08 AM
|
|
Member
|
|
Join Date: Apr 2008
Posts: 91
|
|
|
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?
|
|

04-09-2008, 10:17 AM
|
 |
Moderator
|
|
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 3,583
|
|
|
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.
|
|

04-09-2008, 10:22 AM
|
|
Member
|
|
Join Date: Apr 2008
Posts: 91
|
|
|
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?
|
|

04-09-2008, 10:29 AM
|
 |
Senior Member
|
|
Join Date: Apr 2008
Location: Delhi(India)
Posts: 249
|
|
|
Ok do not use Try Block if you dont want handle Exceptions but you can not use finally block without Try.
|
|

04-09-2008, 10:31 AM
|
|
Member
|
|
Join Date: Apr 2008
Posts: 91
|
|
|
Sanjeev, then we can go for finalize() also to do the cleanup code right?
|
|

04-09-2008, 10:42 AM
|
 |
Senior Member
|
|
Join Date: Apr 2008
Location: Delhi(India)
Posts: 249
|
|
|
Yes you are right,
finally block is only for cleanup with try block.
sanjeev
|
|

04-09-2008, 10:58 AM
|
 |
Moderator
|
|
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 3,583
|
|
|
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.
|
|

04-09-2008, 10:59 AM
|
|
Member
|
|
Join Date: Apr 2008
Posts: 91
|
|
|
Thanks Eranga. I will explore more on this, and will come back. Thank you very much
|
|

04-09-2008, 11:07 AM
|
 |
Moderator
|
|
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 3,583
|
|
|
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.
|
|

04-09-2008, 11:34 AM
|
|
Member
|
|
Join Date: Apr 2008
Posts: 91
|
|
|
Sure, Eranga
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|