我有以下课程:
BusinessException.java (是需要捕获异常并抛出异常的主要异常类)
public class BusinessException
extends Exception
{
private BusinessExceptionInfo faultInfo
public BusinessException(String message, BusinessExceptionInfo faultInfo) {
super(message);
this.faultInfo = faultInfo;
}
public BusinessException(String message, BusinessExceptionInfo faultInfo, Throwable cause) {
super(message, cause);
this.faultInfo = faultInfo;
}
public BusinessExceptionInfo getFaultInfo() {
return faultInfo;
}
}
BusinessExceptionInfo.java
public class BusinessException {
protected ExceptionResponse exceptionResponse;
protected String message;
// getters and setters for these properties
}
ExceptionResponse.java (此类包含异常消息和堆栈跟踪。此类需要填充来自异常的值)
public class ExceptionResponse {
protected String exceptionClass;
protected String exceptionMessage;
protected List<ErrorResponseItem> errorResponseItems;
protected String stackTrace;
// getters and setters for these properties
}
ErrorResponseItem.java
public class ErrorResponseItem {
protected String defaultErrorDescription;
protected List<String> descriptionVariables;
protected String errorCode;
protected SourceSystemFault sourceSystemFault;
// getter and setter methods
}
// SourceSystemFault.java
public class SourceSystemFault {
protected List<String> calloutParameters;
protected String errorCode;
protected String errorDescription;
protected String operationName;
protected String serviceName;
protected String system;
}
MyClass.java (我的类在哪里需要检查并抛出它。如何传递异常消息,从此类堆栈跟踪到ExceptionResponse?) 任何人都可以分享类似问题的例子。这会很有帮助。我使用这些文件来处理项目中的异常。
public MyResponse myMethod(MyRequest req)
throws BusinessException {
}
如何捕获并抛出BusinessException。我是新手,需要帮助。