public class ServiceException extends RuntimeException
在抛出异常时候,务必带上AbstractExceptionEnum枚举
业务异常分为三种
第一种是用户端操作的异常,例如用户输入参数为空,用户输入账号密码不正确
第二种是当前系统业务逻辑出错,例如系统执行出错,磁盘空间不足
第三种是第三方系统调用出错,例如文件服务调用失败,RPC调用超时
| 构造器和说明 |
|---|
ServiceException(AbstractExceptionEnum exception)
不建议直接抛出ServiceException,因为这样无法确认是哪个模块抛出的异常
建议使用业务异常时,都抛出自己模块的异常类
|
ServiceException(String moduleName,
AbstractExceptionEnum exception)
如果要直接抛出ServiceException,可以用这个构造函数
|
ServiceException(String moduleName,
String errorCode,
String userTip)
根据模块名,错误码,用户提示直接抛出异常
|
ServiceException(String moduleName,
String errorCode,
String userTip,
Object data)
携带数据的异常构造函数
|
public ServiceException(String moduleName, String errorCode, String userTip)
public ServiceException(String moduleName, AbstractExceptionEnum exception)
public ServiceException(AbstractExceptionEnum exception)
建议使用业务异常时,都抛出自己模块的异常类
Copyright © 2022. All rights reserved.