C# Exception Handling Best Practices


The best practices for Exception Handling in C# are based on logging the exception. The log should be to logging library to keep a record of the exceptions.

The following are the best practices you should follow while handling exceptions in C# −

  • Log exceptions using log4net, NLog, and other frameworks used for the same purpose. Log exceptions to a file and send the log to various other targets like a database, email, etc.
  • You should log every exception in your application. They help in finding the problems in the LOC.
  • With logging exceptions, you need to also log the contextual details useful for troubleshooting exceptions.
  • Use an exception-monitoring tool to manage and log exceptions. That would allow you to keep all the exceptions at a centralized location and uniquely identify it.
  • With that, you will also get an option to view and search all exceptions added on all servers and applications.

karthikeya Boyini
karthikeya Boyini

I love programming (: That's all I know

Updated on: 19-Jun-2020

198 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements