Exception Handling.
Try Catch ->
// Arithmatic Exception
package Exception_Handling;
public class try_catch {
public static void main(String[] args) {
int a=10,b=0,c;
try{
c=a/b;
System.out.println(c);
}catch(ArithmeticException e){
System.out.println(e);
}
}
}
// NullPointer Exception
package Exception_Handling;
public class try_catch {
public static void main(String[] args) {
String s=null;
try{
System.out.println(s.toUpperCase());
}catch(NullPointerException e){
System.out.println(e);
}
}
}
// NumberFormat Exception
package Exception_Handling;
public class try_catch {
public static void main(String[] args) {
String s="ved";
try{
int a=Integer.parseInt(s);
System.out.println(a);
}catch(NumberFormatException e){
System.out.println(e);
}
}
}
//j
Comments
Post a Comment