Sunday, 17 April 2011

Is an empty catch block legal?

Yes you can leave the catch block without writing any actual code to handle the exception caught.
e.g. The code below is legal but not appropriate, as in this case you will nt get any information about the exception thrown.
try{
//code that may throw the FileNotFoundException
}catch(FileNotFound eFnf){
//no code to handle the FileNotFound exception
}

No comments:

Post a Comment