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.


Popular posts from this blog

php - How should I create my API for mobile applications (Needs Authentication) -

5 Reasons to Blog Anonymously (and 5 Reasons Not To)

Google AdWords and AdSense - A Dynamic Small Business Marketing Duo