aspose file tools*
The moose likes Beginning Java and the fly likes catch and try Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "catch and try" Watch "catch and try" New topic
Author

catch and try

Jello Yao
Greenhorn

Joined: Jan 05, 2003
Posts: 13
Is it legal for a source file which only have try and without any catch blocks?
Thanks!
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Have you tried?
IIRC, a try block needs to be followed by at least one catch *or* finally block, but I might be wrong...


The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
cornel jew
Ranch Hand

Joined: Jul 13, 2002
Posts: 37
Hi
The best way is do some coding and let the compiler answer your question.
Robbie shi
Greenhorn

Joined: Jan 05, 2003
Posts: 28
that is illegal~~
each try block should match a catch block
and the finalize block is optional
--
Robbies
-----------------------------
1.java IDE tool : JawaBeginer
2.Java Jar tool : JavaJar
http://www.pivotonic.com
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
Ilja recalled correctly. A try block must have an associated catch or finally block. So, the catch block is also optional.
As mentioned, the compiler is one of the best ways to discover such requirements of the language.


[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
Raj Neets
Ranch Hand

Joined: Nov 12, 2002
Posts: 46
Hai
A try block must have either finally or catch block or both .Else it will give compile time error.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: catch and try