java - Difference between StackOverflowError and StackOverflowException? -
i have written java code giving me stackoverflowerror:- here in commented portion tried catching exception wasn't able handle it.when can handle stackoverflowerror , stackoverflowexception?
public class testexceptions{ public static void main(string [] arg){ try{ new testexceptions().go(); }catch(error r){system.out.println("error caught:-"+r);} /*try{ new testexceptions().go(); }catch(exception e){system.out.println("exception caught here:-"+e);}*/ } void go(){ system.out.println("go method called:-"); go(); }
}
there nothing called stackoverflow exception. stackoverflowerror. link explains why happens.
difference between error , exception:
an error "indicates serious problems reasonable application should not try catch."
while
an exception "indicates conditions reasonable application might want catch."
refer what difference between errors , exceptions?
you cannot catch error exception catch block. error , exception both have same parent throwable. if catch throwable in catch block,you able catch stackoverflowerror.
but never catch error
Comments
Post a Comment