1.

Exception Handling Best Practices in C#

Answer»

The FOLLOWING are the best practices to handle exceptions in C#:

  • Avoid returning error code. Instead throw exceptions to display them completely.
  • Log the exceptions to a logging library. This is done to keep track of the exceptions occurred. Log it to a file using NLog, Serilog, etc.
  • Log exceptions centrally.
  • You can also log exceptions to the database.
  • View and search all exceptions across all applications.
  • While creating your own exception classes, it would be great if you can atleast the THREE common constructors.
  • Windows Event Log is for logging errors and other information from applications.
  • You need to ensure that the metadata for the exceptions is available to code that is executing remotely while creating user-defined exceptions.
  • View and search all exceptions across all servers.
  • Use the VISUAL Studio Debugger to view all exception.
  • Uniquely identify exceptions to easily BIFURCATE them.


Discussion

No Comment Found