try multiple catch blocks
Demo 1:
package exceptions;
public class TryMultiCatchblock
{
public static void main(String arg[]){
try
{
System.out.println(10/0);
}
catch(ArithmeticException e) //child
{
//code
}
catch(Exception e1) //parent
{
//code
}
// Here exception parent class ArithmeticException child class
}
}
Demo 2:
package exceptions;
public class TryMultiCatchblock
{
public static void main(String arg[]){
try
{
System.out.println(10/0);
}
catch(Exception e) //parent
{
//code
}
catch(ArithmeticException e1) //child (compile time error)
{
//code
}
// Here exception parent class ArithmeticException child class
}
}
1 comments:
give more example
Post a Comment