Error Handling - alexdaube/My-Software-Engineering-Guide GitHub Wiki

Error Handling

Avoid to over use error handling code, manage errors efficiently

Use Exception Instead of error code

  • Simplify the code greatly
  • Not an infinity of conditionals

Use unsigned exception

  • Signed exception break the Opened Closed Principle
  • It has effect on all the users of the class
  • It depends from the language of course. Ex: Go doesn't not have exception classes

Provide context with exception

new IOException(’Imposible d’ouvrir foo.txt’);

Don't use exceptions in the logic

  • Also depends of the language

Try not to return NULL

  • You're asking for trouble when you do
  • Solutions: Null Objects, Maybe Objects, empty objects...
  • Tell don't ask
  • This is not the opinion of everybody in the community

Do not pass null as an argument

  • Leads to ugly code in general

Never kill an exception

  • Creates security leaks