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 try/catch 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 "try/catch" Watch "try/catch" New topic
Author

try/catch

amalip epa
Greenhorn

Joined: Mar 19, 2005
Posts: 7
if there are more than one esceptions in a single try block will all the exception read by the jvm durin the compile time.
John Wolf
Ranch Hand

Joined: Feb 18, 2002
Posts: 64
Amalip,

The jvm follow the order of the exceptions in the code. And, since exceptions are polymorhpic, the catch blocks should be in the order of smallest to biggest or you might get a compilation error.

For example, the following code throws an IOException but the Exception catch block is before the IOException. Since Exception is a supertype of IOException, you would get a compilation error, "Unreachable catch block for IOException. It is already handled by the catch block for Exception."



I hope this helps.

Sumit
[ April 23, 2005: Message edited by: Sumit Sadana ]

SCJP 1.2, SCJP 1.4, SCJA, SCWCD 1.4<br /> <br />------------------------------<br />
amalip epa
Greenhorn

Joined: Mar 19, 2005
Posts: 7
thanx
but my problem is if there are two exceptions in a single try block will the compiler read both exceptions
Kalyani Marathe
Ranch Hand

Joined: Apr 06, 2005
Posts: 72
Compiler will read the most specific one.
amalip epa
Greenhorn

Joined: Mar 19, 2005
Posts: 7
thanx
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: try/catch
 
Similar Threads
Inner class and static members
Static, instance and local variables
What is the best approach to write result set data to flat file?
RUNNING AN EXE THROUGH A JAVA PGM
Another 'Y' game