我有一个关于Java异常处理标准的问题。
代码片段:
public String methodXXX(){
//This method may throw IllegalArgumentexception and arrayoutofboundaryException.
}
在这种情况下,哪些是良好的编码标准?请告诉我原因。 案例1:
public String methodXXX() throw IllegalArgumentexception,ArrayoutofBoundaryException.{
//This method may throw IllegalArgumentexception and arrayoutofboundaryException.
}
情景2:
public String methodXXX()throws Exception{
//This method may throw IllegalArgumentexception and arrayoutofboundaryException.
}
为什么我在这里提到Case2:我们可能不会预期在运行时发生其他异常,因为Exception是所有异常的父类,所以Case2更可取吗? 如果是的话,在哪些情况下Case1是可行的? 您能否向我解释一下性能方面的观点?