c# - try{} catch(Exception e){} VS try{} catch(Exception e){ throw;} - What the difference? -
c# - try{} catch(Exception e){} VS try{} catch(Exception e){ throw;} - What the difference? -
this question has reply here:
the difference between try/catch/throw , try/catch(e)/throw e 4 answersi got here next code anti-pattern. right?
try { //something } catch(exception e) { //something }
and why improve use
try { //something } catch(exception e) { //something throw; }
?
i got sec variant using re-throwing exception (logging example), if need re-throw same exception why not utilize next code?
try { //something } catch(exception e) { //something throw e; }
this re-throw same exception , maintain stack trace. create debugging easier.
catch(exception e) { //something throw; }
this rethrow exception, you'll lose stack trace.
catch(exception e) { //something throw e; }
this silently swallow exception. want when you're catching specific exception rather exception
. should have reason doing so.
try { //something } catch(exception e) { //something }
c# anti-patterns
Comments
Post a Comment