I was studying the Exception
chapter in java and wondering if it does any good to put some throws UncheckedException
after a method signature. I can see that with checked exceptions that kind of a statement is necessary to compile the code and with try, catch and finally all exceptions can be handled. But my question is what difference if at all does it make to add a throws UncheckedException
after a method signature?
for example, to compile the following code with a File
object, you need to have a checked exception:
void main(String args[])throws IOException{
File f=new File("c:\\java\\xyz.txt");
}
But what effect such a statement has in the following code:
public static int method1(String str)throws NumberFormatException{
int i=Integer.parseInt(str);
return i;
}
thanks in advance.