Exception Handling in C#

Previous: Examples

Always make sure to properly handle exceptions in your C# code, whenever you sense a code block that might generate an error, due to any reason. When handling exceptions, add the catch block beginning with the most specific exception that you think it will occur, then go less specific until most generic. Avoid catching exceptions without taking the needed actions and follow the practice of logging all your exceptions.

Article has been ported from

Create your playground on
This playground was created on, our hands-on, knowledge-sharing platform for developers.
Go to