Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

checked and unchecked exceptions

bethelNov 16 2010 — edited Nov 17 2010
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.
This post has been answered by 796440 on Nov 17 2010
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 15 2010
Added on Nov 16 2010
3 comments
713 views