public class Thrower {
public static void main(String[] args) throws Exception {
sneakyThrow(new Exception("This is a checked exception"));
throw new Exception();
}
public static void sneakyThrow(Throwable t) {
for(int i=0; i<10; i++)
System.out.println("get"+t);
}
}
If you change this code like the above, the main method does throw the checked exception at run time. You can declare a Runtime exception too.
In order to have the method throw an exception, put "throw new XXException()" in a line, and declare it in the method. This will make the method throw the exception.