what does unchecked exception mean in java -


well, book got below lines:

java defines several exception classes inside standard package java.lang. general of these exceptions subclasses of standard type runtimeexception. since java.lang implicitly imported java programs, exceptions derived runtimeexception automatically available.

furthermore, need not included in method's throws list.

so, doesnt mean dont need try catch block?

i have done following code, showing error:

 exception in thread "main" java.lang.arithmeticexception: / 0 @ arithcls.main(arithcls.java:10) 

code:

import java.lang.*; public class arithcls {  public static void main(string[] args)     {     int a=20;     int b=0;     int c = a/b;     system.out.println("after code"); } } 

an unchecked exception 1 not checked ;-p

no, in seriousness, it's exception compiler/jvm not force code check for. these (always?) runtime exception, such nullpointerexception.

a runtime exception exception can't anticipate and/or handle before execution time -- , therefore crash program's execution.

you, in own code, can explicitly "check" them using try/catch block, it's better practice handle these via null checks, etc.

if (str != null) {      // stuff } 

Comments

Popular posts from this blog

c++ - How to add Crypto++ library to Qt project -

jQuery Mobile app not scrolling in Firefox -

How to use vim as editor in Matlab GUI -