public class MyClass{
public static void main(String[] args) {
throw new ArithmeticException();
}
}
import java.io.FileNotFoundException;
public class MyClass{
public static void main(String[] args) throws FileNotFoundException {
throw new FileNotFoundException();
}
}
when i compile the second code without declaring throws, i'll get 'Unhandled exception type FileNotFoundException' compile error. This may be because of FileNotFoundException is checked.
How do the compiler understand that FileNotFoundException is checked and ArithmeticException is unchecked? I went through source code of both classes, but coudn't find anything special.
One is in the java.lang package and the other in java.io.
One extends RuntimeException and other extends IOException, and both these are extended from Exception class.