java - Is catching a specific exception less expensive than catching a generic one? -
say i'm loading bitmap onto android device. there many possible exceptions can thrown. sake of simplicity let's take nullpointerexception
, outofmemoryerror
.
now have 2 pieces of code.
code 1
try{ //load bitmap } catch(exception e) { //do }
code 2
try{ //load bitmap catch (nullpointerexception e) { //do } catch(outofmemoryerror e) { //do else }
is 1 piece of code more effective other performance wise? if so, why?
from byte code point of view more effective (less code) first one.
but should never @ performance in way.
if have same behavior type of exceptions, should use first bunch of code, in other way, second one.
in byte code have following code responsible catching eceptions:
l2 linenumber 7 l2 frame same1 java/lang/nullpointerexception astore 1 goto l4 l3 linenumber 9 l3 frame same1 java/lang/exception astore 1 l4
so each exceptions has code responsible catching that, said such minor difference shouldn't taken consideration.
Comments
Post a Comment