Header Ads Widget

WAP to handle in exception by using try with multiple catch

 Code:-


class exceptionhandling
{
public static void main(String []args)
{
try
{
int a[]=new int[5];
a[5]=30;
}
catch(ArrayIndexOutOfBoundsException e)
{
System.out.println("Out of index");
}
catch(ArithmeticException e)
{
System.out.println("This is an ArithmeticException");
}
catch(NullPointerException e)
{
System.out.println("This is an Null pointer exception");
}
catch(NumberFormatException e)
{
System.out.println("Wrong Input format");
}
}
}

Output:-

Out of index




Recommended Post:

Full C course:-    

Key points:-

Cracking the coding interview:-

 Array and string:-

Tree and graph:-

Hackerearth Problems:-

Hackerrank Problems:-

Data structure:-

 MCQs:-