• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Exception Handling

 
Vatsal Upadhyaya
Greenhorn
Posts: 18
Android Netbeans IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package food;

/**
*
* @author Vatsal
*/
public class LABEL {
public static void main(String args[])
{
int y=0;
LABEL a=new LABEL();
try
{
y=a.div();
}

catch(ArithmeticException e)
{
System.out.println("Error");
}
}
/**
*
* @return
*/
public int div()
{
System.out.println("5/3");
return (5/3);
}
}

This code is running but it only gives output "5/3"

while instead of ArtithmeticException if i write only Exception in catch i am getting the output
5/3
Error

why...???
 
Jack McLaren
Greenhorn
Posts: 13
Mac Mac OS X Mac PPC
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is nothing about exception.It will not even compile.You are trying to assign float value into int variable without casting.
 
Vatsal Upadhyaya
Greenhorn
Posts: 18
Android Netbeans IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jack McLaren wrote:There is nothing about exception.It will not even compile.You are trying to assign float value into int variable without casting.


sorry...there is int instead of float..
 
Ben Pheonix
Ranch Hand
Posts: 46
1
Java Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
Please use Code tags
It makes your code easier to understand and read.
Regards,
Ben
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic