File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Is it possible to have try with out catch or finally Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Is it possible to have try with out catch or finally" Watch "Is it possible to have try with out catch or finally" New topic
Author

Is it possible to have try with out catch or finally

sadasiva kumar
Ranch Hand

Joined: Oct 30, 2003
Posts: 91
Is it possible to have try without catch or finally .please any can exaplain with example




regards
SADASIVAKUMAR UTTI


SADASIVAKUMAR UTTI, SCJP1.4
A bend in the road is not the end of the road ... unless you fail to make the turn.
Gaurav sachdeva
Greenhorn

Joined: Sep 08, 2006
Posts: 1
No it is not possible to have try without catch block or finally block.

You can write in 3 ways.

Either try and catch(single or multiple)

Either try and finally

Either try , catch and finally in the same sequence.
sadasiva kumar
Ranch Hand

Joined: Oct 30, 2003
Posts: 91
Is it possible to have only try with IOException
Hans Beck�rus
Greenhorn

Joined: Aug 23, 2006
Posts: 24
As said before try needs either a catch a finally or both.
What really do you want to accomplish? Why not do a try w/ an
empty finally body. Or have I totally misunderstood your
question?
Shang Lee
Greenhorn

Joined: Aug 17, 2006
Posts: 20
Hi Sadasiva,

You ask for examples so based on what Gaurav have mentioned earlier, you can code something like this:



or



or



It is illegal to have "try" without "catch" or "finally". You need to have at least one of them - "catch" or "finally".


Best Wishes,<br />Shang
sadasiva kumar
Ranch Hand

Joined: Oct 30, 2003
Posts: 91
Hi,
Thanks to every one.Now i understood about try clearly.Thanks to shang for giving explanation with example.




regards
SADASIVAKUMAR UTTI
yogesh gargate
Greenhorn

Joined: Aug 18, 2006
Posts: 17
Hi,
Try to understand the meaning of "try" block.
It is the block where exception may occure, if you don't provide any code to handle it, your program will stop. So you need to give the code to handle the exception, and which is given in "catch" block. So there should be "try" with either "catch" or "finally" or both.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Is it possible to have try with out catch or finally