Skip to content

Exceptions Best Practices

Fundamentals

Read and be familiar with the following:

Best Practices

Engineers should follow Microsoft Exception Best Practises.

Engineers should not throw System.Exception, System.SystemException, System.NullReferenceException, or System.IndexOutOfRangeException in their own code.

Engineers should throw predefined Exceptions when it is suitable to do so e.g. ArgumentNullException

Engineers should only create Exceptions when predefined ones do not exist, but should prioritise specificity over a less detailed generic predefined exception. e.g. Create custom OutOfMoneyException instead of InvalidOperationException("OutOfMoney")

Engineers should only catch specific types of exceptions not a general Exception catch.

Engineers should use finally blocks to clean up resources even if no exceptions have been caught.

Comments