我正在查看以下代码段中重新编译了哪种类型的异常。 虽然我不确定如何去做,或者甚至可能。检查APEX异常类型
try {
//SOME LOGIC
} catch (exception ex) {
System.debug(//EXCEPTION TYPE);
}
有没有人有任何建议或建议?
我正在查看以下代码段中重新编译了哪种类型的异常。 虽然我不确定如何去做,或者甚至可能。检查APEX异常类型
try {
//SOME LOGIC
} catch (exception ex) {
System.debug(//EXCEPTION TYPE);
}
有没有人有任何建议或建议?
一些摸索我找到了答案后,
try {
//SOME LOGIC
} catch (Exception ex) {
System.debug(ex.getTypeName());
}
方法很好地诀窍。
我很抱歉没有指定我在Apex工作在我的问题。
try {
//SOME LOGIC
} catch (Exception ex) {
System.err.println(ex.getClass().getName());
}
几件事情:
首先,在您的catch
块中指定例外。在语义上,type
包括Exception
不属于驼峰的情况。
其次,可以通过Exception.getClass().getName()
获得异常类型:
catch (Exception exception) {
System.out.println(exception.getClass().getName());
// exception.printStackTrace();
// throw exception;
}
指定者:
http://docs.oracle.com/javase/7/docs/api/java/lang/Exception.html
感谢您的回答JamesB,但我得到以下错误, 方法不存在或不正确的签名:[例外] .getClass() – Daft
其他的东西一定是你的代码有问题。 getClass方法属于java.lang.Object,所以每个对象都有这个方法。 – JamesB