C# Catching Exceptions Guideline (updated for C# 6.0)

The article proposes and summarizes guidelines for exception handling / catching exceptions.

  • AVOID catching exceptions that you’re unable to handle fully.
  • AVOID hiding (discarding) exceptions you don’t fully handle.
  • DO use throw to rethrow an exception; rather than throw inside a catch block.
  • DO set the wrapping exception’s InnerException property with the caught exception unless doing so exposes private data.
  • CONSIDER an exception condition in favor of having to rethrow an exception after capturing one you can’t handle.
  • AVOID throwing exceptions from exception conditional expression.
  • DO use caution when rethrowing different exceptions.
  • Rarely use System.Exception and general catch blocks—except to log the exception before shutting down the application.
  • AVOID exception reporting or logging lower in the call stack.


Sources:

Comments

Popular posts from this blog

SQL Server Setup: Windows Firewall warning (Ports)

SQL Server 2014 Enterprise Edition: Server Setup: Feature Selection

How to read an assembly.dll.config