一. 问题
dubbo项目中, 定义了全局异常处理类以后, 在provider中抛出的自定义异常在consumer中捕获不到
二. 原因
dubbo源码中对异常进行了异常过滤处理, 源码入下:
package com.alibaba.dubbo.rpc.filter;
import ...
@Activate(group = Constants.PROVIDER)
public class ExceptionFilter implements Filter {
private final Logger logger;
public ExceptionFilter() {
this(LoggerFactory.getLogger(ExceptionFilter.class));
}
public ExceptionFilter(Logger logger) {
this.logger = logger;
}
public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {
try {
Result result = invoker.invoke(invocation);
if (result.hasException() && GenericService.class != invoker.getInterface()) {
try {
Throwable exception = result.getException();
// 如果是checked异常,直接抛出
if (!(exception instanceof