Sunday, February 28, 2010

Exception Handling Best Practices

 

  • Serialize exceptions, so that they are available across app domains.
  • As far as possible, let the exception be in the same assembly that throws it.
  • Use at least the 3 common constructors that Exception class provides.
  • Use pre-defined exceptions if possible instead of custom exceptions.
  • Return null instead of exception for common errors
  • Categorize exceptions in a hierarchy based on modules.
  • Include localized description string for exception.
  • Provide Exception properties for programmatic access.
  • Do not catch generic exceptions when specific exceptions can be caught.
  • Check for ErrorCode property in COMException for HResult value.
  • Make COM objects implement IErrorInfo, so that they can be access in .NET

No comments: