java - Is catch block able to catch Throwable (both error and exception) -
in 1 of interview, asked me, possible write throwable in catch() this
try{ code } catch(throwable t) { }
i said yes. not give compile time error jvm not handle if there occur error
(sub class of throwable ), since errors irreversible conditions can not handled jvm. further asked use of writing throwable .
please give me proper reply can use throwable in catch. if yes why.
it possible catch throwable
. , yes, catch instances of java.lang.error
problem when comes e.g. outofmemoryerror
's. in general i'd not catch throwable
's. if have to, should @ highest place of call stack, e.g. main
method (you may want catch it, log it, , rethrow it).
i agree argumentation, not make sense catch events you're not able handle (e.g. outofmemoryerror). nice post here.
Comments
Post a Comment