import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
@ControllerAdvice
public class GlobalException {
@ExceptionHandler(Throwable.class)
@ResponseBody
public Object networkExceptionHandle(Throwable e){
if(e instanceof SomeException){
return "自定义返回对象";
}
//其它异常在这里判断。。。
else if (e instanceof RuntimeException || e instanceof Exception){
return "Exception时自定义返回对象";
} else {
return "其它情况自定义返回对象";
}
}
}