NumberFormatException and Exception hierarchy.
When we catch an exception with catch clause, we should catch exception from narrow to wide. Otherwise compiler will give a compilation error.
Here is a simple example to illustrate the NumberFormatException and usage of Exception hierarchy.
class NumberFormat{
void throwExcep(){
String s=null;
int [] val={1,2,3,4,5};
String ss="ABCD";
try{
int i=Integer.parseInt(ss);
}
catch(NumberFormatException np){
System.out.println("NumberFormat");
}
catch(ArrayIndexOutOfBoundsException ae){
System.out.println("ArrayIndexOutOfBounds");
}
catch(Exception e){
System.out.println("Exception");
}
}
public static void main(String args[]){
NumberFormat nf= new NumberFormat();
nf.throwExcep();
}
}
When we catch an exception with catch clause, we should catch exception from narrow to wide. Otherwise compiler will give a compilation error.
Here is a simple example to illustrate the NumberFormatException and usage of Exception hierarchy.
class NumberFormat{
void throwExcep(){
String s=null;
int [] val={1,2,3,4,5};
String ss="ABCD";
try{
int i=Integer.parseInt(ss);
}
catch(NumberFormatException np){
System.out.println("NumberFormat");
}
catch(ArrayIndexOutOfBoundsException ae){
System.out.println("ArrayIndexOutOfBounds");
}
catch(Exception e){
System.out.println("Exception");
}
}
public static void main(String args[]){
NumberFormat nf= new NumberFormat();
nf.throwExcep();
}
}
Hello! Do you know if they make any plugins to safeguard against hackers? I'm kinda paranoid about losing everything I've
ReplyDeleteworked hard on. Any suggestions?
technology services