here are 2 versions of same program:
version 1:
package dutt;
class App{
static void demo(){
try{
throw new NullPointerException("generic");
}catch(NullPointerException q){
System.out.println("caught inside demo");
throw q;
}
}
public static void main(String args[]){
try{
demo();
}catch(NullPointerException q){
System.out.println("caught inside main: " +q);
}
}
}
version 2:
package dutt;
class App{
static void demo(){
try{
throw new Exception("generic");
}catch(Exception q){
System.out.println("caught inside demo");
throw q;
}
}
public static void main(String args[]){
try{
demo();
}catch(Exception q){
System.out.println("caught inside main: " +q);
}
}
}
the only difference is I had used generic Exception class for version2 of program. while the version1 compiles without error, i get error in the version2: [Unhandlled exception type Exception]. i couldn't understand the reason. please help..
IDE used: Eclipse
version 1:
package dutt;
class App{
static void demo(){
try{
throw new NullPointerException("generic");
}catch(NullPointerException q){
System.out.println("caught inside demo");
throw q;
}
}
public static void main(String args[]){
try{
demo();
}catch(NullPointerException q){
System.out.println("caught inside main: " +q);
}
}
}
version 2:
package dutt;
class App{
static void demo(){
try{
throw new Exception("generic");
}catch(Exception q){
System.out.println("caught inside demo");
throw q;
}
}
public static void main(String args[]){
try{
demo();
}catch(Exception q){
System.out.println("caught inside main: " +q);
}
}
}
the only difference is I had used generic Exception class for version2 of program. while the version1 compiles without error, i get error in the version2: [Unhandlled exception type Exception]. i couldn't understand the reason. please help..
IDE used: Eclipse