mercredi 7 janvier 2015

How to differentiate between exceptions coming from system and business logic?


I would like to differentiate between exceptions coming from business logic like



  • requested database records does not exist

  • attempt to store invalid business data (validation failed)

  • provided CSV file has wrong format


from system exceptions like



  • database connection timeout

  • file I/O error


So I would like to handle business logic exceptions gracefully, differently from standard system exceptions. No output of stack trace, no logging of "critical" category, etc.


The best idea I could figure out was to create common ancestor for business exceptions and check it in the handler. I think this was orgininal purpose of ApplicationException which is now deprecated. Do you think I can resurrect it for the purpose or is there some better approach?





Aucun commentaire:

Enregistrer un commentaire