处理来自 Throwable catch 的 NullPointerException 的最佳方法是什么。
public void run() {
try{
}catch (Throwable e){
// e.getMessage() is equal to null
// and sends a NullPointerException
if (e.getMessage().equals(“something“){
}
}
}
做了一些研究,我发现here 如果某些异常发生的次数足够多,JIT 编译器将优化掉堆栈跟踪
我以为我可以在 Throwable catch 中抛出异常,但它看起来不太干净。
谢谢!
最佳答案
不要编写可能引发 NullPointerException 的代码。
public void run() {
try {
} catch (Throwable e){
if (“something“.equals(e.getMessage()) {
}
}
}
或
public void run() {
try {
} catch (Throwable e){
if (e.getMessage() != null && e.getMessage().equals(“something“) {
}
}
}
关于java - 处理来自 Throwable catch 的 NullPointerException 的最佳方法? (安卓),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24996838/