wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Exception Handling 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 "Exception Handling" Watch "Exception Handling" New topic
Author

Exception Handling

Vatsal Upadhyaya
Greenhorn

Joined: Jul 08, 2013
Posts: 18

/*
* 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...???


Avenger
Jack McLaren
Greenhorn

Joined: Jun 17, 2013
Posts: 13

There is nothing about exception.It will not even compile.You are trying to assign float value into int variable without casting.


I AM THE LAW.
Vatsal Upadhyaya
Greenhorn

Joined: Jul 08, 2013
Posts: 18

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

Joined: Dec 11, 2012
Posts: 46
    
    1

Hi
Please use Code tags
It makes your code easier to understand and read.
Regards,
Ben


Twitter:ben_pheonix
 
GeeCON Prague 2014
 
subject: Exception Handling