What is your usual exception hierarchy?

My question is: how would you create an exception hierarchy in your application?

Architecture development of the application, from my point of view, we could have three types of exceptions:

  • inline (ex: InvalidOperationException)
  • custom internal system errors (database transaction failed during commit, DbTransactionFailedException exception)
  • custom business exceptions (BusinessRuleViolationException)

Class hierarchy:

  • An exception
    • MyAppInternalException
      • DbTransactionFailedException
      • MyServerTimeoutException
      • ...
    • MyAppBusinessRuleViolationException
      • UsernameAlreadyExistsException
      • ...

where only MyAppInternalException and MyAppBusinessRuleViolationException will be detected.

+3
2

E, F, , E , , E, F. , , , E, , E.

, . , - - :

  • ConfigurationException - , . . config . ( , ).
  • InfrastructureException - , , .. , .
  • DataException - - . (, , ) .

, . , . , , catch, .

+4

"UsernameAlreadyExistsException"

, . .. . MyAppBusinessRuleViolationException.

,

+2

Source: https://habr.com/ru/post/1743341/


All Articles