我的问题是:您将如何在应用程序中创建异常层次结构?
从我的角度来看,设计应用程序的架构时,我们可以有三种类型的异常:
1. 内置异常(例如:InvalidOperationException); 2. 自定义内部系统故障(例如:数据库事务提交失败,DbTransactionFailedException); 3. 自定义业务异常(例如:BusinessRuleViolationException)。
类层次结构如下:
- Exception - MyAppInternalException - DbTransactionFailedException - MyServerTimeoutException - ... - MyAppBusinessRuleViolationException - UsernameAlreadyExistsException - ...
只有 MyAppInternalException 和 MyAppBusinessRuleViolationException 会被捕获。
从我的角度来看,设计应用程序的架构时,我们可以有三种类型的异常:
1. 内置异常(例如:InvalidOperationException); 2. 自定义内部系统故障(例如:数据库事务提交失败,DbTransactionFailedException); 3. 自定义业务异常(例如:BusinessRuleViolationException)。
类层次结构如下:
- Exception - MyAppInternalException - DbTransactionFailedException - MyServerTimeoutException - ... - MyAppBusinessRuleViolationException - UsernameAlreadyExistsException - ...
只有 MyAppInternalException 和 MyAppBusinessRuleViolationException 会被捕获。