Java Exception

By | February 19, 2011

Simple java program to show how exception works

public class exception
{
public static void main(String[] args)
{
try
{
int a = 10;
int b = 10/0;
}
catch(ArithmeticException e)
{
System.out.println(“Exception Caught ” + e);
}
}
}
The output will be like you expect
Exception Caught java.lang.ArithmeticException: / by zero

Leave a Reply

Your email address will not be published. Required fields are marked *