I have written following sample class to experiment with exception. I have two identical methods, one throws RuntimeException whereas one with Exception not compiling.
Sample code
public class Test{
public static void main(String... args){
System.out.println(3%-2);
System.out.println(4%-2);
Test t1 = new Test();
t1.mtd1(101);
t1.mtd2(101);
}
public int mtd1( int i) throws RuntimeException{
System.out.println("mtd");
return i;
}
public int mtd2( int i) throws Exception{
System.out.println("mtd");
return i;
}
}
Error
C:\Java\B-A>javac Test.java
Test.java:10: error: unreported exception Exception; must be caught or declared to be thrown
t1.mtd2(101);
^
1 error