

BaseAppException:受檢異常基類BaseAppRuntimeException:非受檢異常基類WrapperedAppException:包裝第三方/JDK 異常轉為受檢errorCode(格式 LDD600-\d{1,5}),前端按碼顯示友好提示CoreContextFactory)Class<?> → ExceptionDefinition(含 errorCode、handler 名稱集合)public interface ExceptionHandler {
void handle(ExceptionContext ctx, Exception ex, Request req, Response resp);
}
內置 ConsoleHandler(控制台輸出)、LogHandler(日誌記錄)等,業務可自定義實現(如郵件通知、鉤子調用)。
所有 Action/Service 執行委託給 ActionBroker,其 execute() 內部 try-catch 捕獲所有異常,委託 ExceptionContext 獲取對應 Handler 鏈執行處理,最後封裝 Response 返回前端。

<xsd:complexType name="exceptionType">
<xsd:sequence>
<xsd:element name="level" default="error" minOccurs="0">...</xsd:element>
<xsd:element name="handler" maxOccurs="unbounded">...</xsd:element>
</xsd:sequence>
<xsd:attribute name="errorCode">
<xsd:simpleType>
<xsd:restriction base="xsd:string">
<xsd:pattern value="LDD600-\d{1,5}.*"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:attribute>
<xsd:attribute name="class" type="xsd:string" use="required"/>
</xsd:complexType>
實現 NamespaceHandler + BeanDefinitionParser 解析自定義標籤,註冊為 Spring Bean。
@Target({ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface Exceptional {
String errorCode();
Class<? extends ExceptionHandler>[] handlers();
}
ExceptionalAnnotationBeanPostProcessor 實現 BeanPostProcessor,掃描帶 @Exceptional 的異常 Bean,啟動時自動註冊至 ExceptionContext。
JMock 單元測試覆蓋:
ConfigException errorCode 為 LDD600-00002框架將「異常定義、錯誤碼分配、處理器綁定」前置為配置/元數據,業務代碼專注於拋出具體異常類,實現關注點分離。雙模式配置兼顧集中管理(XML)與代碼內聚(Annotation),Spring 原生集成零侵入,適合中大型項目標準化異常治理。