| Author |
can we define try without finally
|
Nidhi Jain
Ranch Hand
Joined: Mar 26, 2006
Posts: 31
|
|
Hi, I know we can define try without catch but can we define try without finally? Kindly reply...
|
 |
Veeresh Hosur
Ranch Hand
Joined: Dec 18, 2007
Posts: 32
|
|
If catch block is there then finally block is optional. If catch block is not there then finally block is mandatory. Thanks Veeresh
|
 |
Nidhi Jain
Ranch Hand
Joined: Mar 26, 2006
Posts: 31
|
|
|
is that means try should be followed by any one thing either catch or finally?Rectify me if i understood wrong.
|
 |
Peter Chase
Ranch Hand
Joined: Oct 30, 2001
Posts: 1970
|
|
|
"try" cannot exist on its own. It must be followed by one or more "catch" blocks and/or a "finally". You can, and often do, have both "catch" and "finally".
|
Betty Rubble? Well, I would go with Betty... but I'd be thinking of Wilma.<br /> <br />#:^P
|
 |
Jesper de Jong
Java Cowboy
Bartender
Joined: Aug 16, 2005
Posts: 12921
|
|
A try-block should be followed by either a catch-block, a finally-block, or both. Note: It's very easy to try this out yourself. Write a small test program with a try-block, and add or leave out a catch- or finally-block. Try to compile it and see what the compiler says. Experimenting yourself is important when you learn Java. Trying it out for yourself is one of the best ways to learn things.
|
Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
|
 |
 |
|
|
subject: can we define try without finally
|
|
|