aspose file tools*
The moose likes Beginning Java and the fly likes can we define try without finally Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "can we define try without finally" Watch "can we define try without finally" New topic
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.
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14428
    
  23

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 8 API documentation
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: can we define try without finally