Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Is it possible to have try with out catch or finally

 
sadasiva kumar
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is it possible to have try without catch or finally .please any can exaplain with example




regards
SADASIVAKUMAR UTTI
 
Gaurav sachdeva
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is it possible to have only try with IOException
 
Hans Beckļæ½rus
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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".
 
sadasiva kumar
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
GauravKapoor Kapoor
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is possible to write try WITHOUT Catch/Finally. AutoClosable resources.


 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic