• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

regarding arithmetic exception

 
shreya prabhu
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
try
{
int x=0;
int y=9/x;

}
catch(ArithmeticException ex)//line1
{
System.out.println(ex.toString());
System.out.println("arithmetic exception");
}
System.out.println("finished");

i thought the ouput would be arithmetic exception finished
but at line 1 i am getting a error cannot convert from arithmeticexception to throwable.can anyone please clear my doubt
 
deepak adlakha
Ranch Hand
Posts: 325
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i got this output when i ran this program.


java.lang.ArithmeticException: / by zero
arithmetic exception
finished


I ran jdk 1.4.2_05 version.
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You code compiles and runs (on Java 6.0):


[ March 20, 2007: Message edited by: Barry Gaunt ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic