java - Compilation Error while using throw keyword -
sample code:1
public class classtest { public static void main(string[] args) { throw new java.lang.arithmeticexception(); } } ----no compilation error above code, compiler not asking handle exception
sample code:2
public class classtest { public static void main(string[] args) { throw new java.lang.exception(); } } --compiler wants handle exception using try-catch or throws.
can explain behavior of compiler.i think because need mention xyzexception class(other exception class).
arithmeticexception runtimeexception , not checked compiler. exception checked , therefore prevent compilation if rules violated, such not handling method throws exception.