c# - Does more specific exception handling improve performance? -


if can catch more specific exception prevent clr doing work , benefit performance wise ? if know might socket exception not care handling differently other exception better still have more specific catch ? working on microframework small improvements in performance , resources worth asking about.

 catch (system.net.sockets.socketexception netex)             {              }   catch (exception ex)             {              } 

i not think in terms of performance.

from code correctness perspective: should catch specific exception can.

when catch exception exception handler swallow any exception if not prepared handle it. imagine argumentnullexception thrown. catch block swallow , cause confusion.

if prepared handle socketexception catch that. if less performant it. code correctness not sacrifice such miniscule performance gain*

* or no performance gain @ - almost there zero execution time performance implication @ all. did benchmark on computer , performance more or less equal. not comprehensive test enough confirm instinct. can run own benchmark using technique similar this one


Comments

Popular posts from this blog

yii2 - Yii 2 Running a Cron in the basic template -

asp.net - 'System.Web.HttpContext' does not contain a definition for 'GetOwinContext' Mystery -

mercurial graft feature, can it copy? -