In this tutorial how to handle Exception using Try and Catch Block in Core Java is shown.
Code:
ExceptionDemo.java
class ExceptionDemo
{
public static void main(String args[])
{
int a=0;
int b=5;
System.out.println(“Message1”);
try
{
System.out.println(b/a);
}
catch(ArithmeticException ae)
{
System.out.println(ae.getMessage());
}
catch(Exception e)
{
System.out.println(e.getMessage());
}
System.out.println(“Message2”);
}
}