Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

try/catch

 
amalip epa
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
amalip epa
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Compiler will read the most specific one.
 
amalip epa
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanx
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic