我想知道这两个块之间是否存在差异或性能问题:
try{
return Integer.parseInt(numAsString);
}catch (Exception e){
return onErrorInt;
}
Run Code Online (Sandbox Code Playgroud)
和
try{
return Integer.parseInt(numAsString);
}catch (NumberFormatException e){
return onErrorInt;
}
Run Code Online (Sandbox Code Playgroud)
有时甚至在尝试内部有许多例外,例如:
try{
// open file then try to close
// try to parse integer
// another kind of exception throwing funcitons
}catch (Exception e){
return onErrorInt;
}
Run Code Online (Sandbox Code Playgroud)
和
try{
// open file then try to close
// try to parse integer
// another kind of exception throwing funcitons
}catch (NumberFormatException e){
return // something;
} catch (IOException e){
// return same thing in the exception above
}
Run Code Online (Sandbox Code Playgroud)
.
我正在做的是系统将每天24小时运行,每天重启1次.
在很多地方,我不关心Exception的类型,我只需要让我的应用程序一直运行.所以主要是关于性能的问题.