In the below code i had commented catch part.
so i am getting the below error
--------------
D:\prabhu@java>javac MyException1.java
MyException1.java:4: unreported exception BadFoodException; must be caught or declared to be thrown
try{checkFood(args[0]);}
^
1 error
------------
class BadFoodException extends Exception{}
public class MyException1{
public static void main(
String[] args){
try{checkFood(args[0]);}
/*catch(BadFoodException e){
e.printStackTrace();
}*/
finally{System.out.println("finally");}
}
static void checkFood(String str) throws BadFoodException{
if (str.equals("nofood")){
throw new BadFoodException();
}
else{
System.out.println("i like it");
}
}
}
-----------------------------
my query:
1.try should have either catch or finally.so if remove catch why the code not working,finally is still there know.
Please clarify.
prabhu