try
块抛出的异常更通用的 catch
块。
示例:
try {
File file = new File(pathToFile);
return file.getAbsolutePath();
}
catch (Exception ex) { // 警告:'Exception' 的 'catch' 范围过广,屏蔽异常 'RuntimeException'
return defaultFilePath;
}
在应用快速修复后:
try {
File file = new File(pathToFile);
return file.getAbsolutePath();
}
catch (RuntimeException ex) {
return defaultFilePath;
}
配置检查: