我的问题是关于try-catch块的简单除法示例.你看到第一行尝试?如果我将这两个变量中的任何一个转换为double,则程序无法识别catch块.在我看来,我是否必须执行捕获块.这段代码有什么问题?
public static void main(String[] args) {
int pay=8,payda=0;
try {
double result=pay/(double)payda; // if I cast any of the two variables, program does not recognize the catch block, why is it so?
System.out.println(result);
System.out.println("inside-try");
} catch (Exception e) {
System.out.println("division by zero exception");
System.out.println("inside-catch");
}
}
Run Code Online (Sandbox Code Playgroud)