如何在 Java 中传递带有一些附加数据的自定义 Throwable



这只接受可抛出的类型>

Instrumentation.reportError(exception)

我创建了自定义异常类:

public class AppdIdentityTrackException extends Throwable {

public AppdIdentityTrackException(){
super();
}
public AppdIdentityTrackException(int responseCode,String URl,String errorMessage){
this.responseCode=responseCode;
this.URl=URl;
this.errorMessage=errorMessage;
}

并像这样传入方法;

private void sendAppDTrackData(Response response, String pageName, String errorMessage)  {
try {
throw new AppdIdentityTrackException(1,"","");
} catch (AppdIdentityTrackException exception) {
Instrumentation.reportError(exception);
}
}

但是例外不是表现得像可投掷类型的对象,任何人都可以建议我如何通过可投掷和传递可投掷类型的物体。

如果你正在寻找消息字符串,你可以覆盖throwable的getMessage((方法。

@Override
public String getMessage() {
return responseCode + " " + URl + " " + errorMessage;
}

如果是其他事情,我们将需要有关Instrumentation.reportError(string(正在做什么的更多信息。

最新更新