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

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -