Java try catch blocks -


here simple question :

what think of code use try catch every instruction ?

void myfunction() {     try {         instruction1();     }     catch (exceptiontype1 e) {         // code     }     try {         instruction2();     }     catch (exceptiontype2 e) {         // code     }     try {         instruction3();     }     catch (exceptiontype3 e) {         // code     }     try {         instruction4();     }     catch (exceptiontype4 e) {         // code     }      // etc } 

i know that's horrible, want know if decreases performance.

try this: (i know doesn't answer question, it's cleaner)

void myfunction() { try {     instruction1();     instruction2();     instruction3();     instruction4(); } catch (exceptiontype1 e) {     // code } catch (exceptiontype2 e) {     // code } catch (exceptiontype3 e) {     // code } catch (exceptiontype4 e) {     // code }  // etc } 

Comments

Popular posts from this blog

c# - How to set Z index when using WPF DrawingContext? -

razor - Is this a bug in WebMatrix PageData? -

visual c++ - Using relative values in array sorting ( asm ) -