小编Ank*_*kit的帖子

为什么不打印此例外?为什么会出现错误?

如果我试图打印"a"的值,为什么显示错误?为什么异常会成为错误?

class Ankit1
{
    public static void main(String args[])
    {
        float d,a;
        try
        {
            d=0;
            a=44/d;
            System.out.print("It's not gonna print: "+a); // if exception doesn't occur then it will print and it will go on to the catch block
        }
        catch (ArithmeticException e)
        {
            System.out.println("a:" + a); // why is this an error??
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

java exception

4
推荐指数
1
解决办法
153
查看次数

Java是否在不使用try和catchblock的情况下自动处理异常?

这段代码显示异常:

Exception in thread "main" java.lang.ArithmeticException: / by zero
        at Ankit2.main(Ankit2.java:6)
Run Code Online (Sandbox Code Playgroud)

它为什么以及如何发生?不使用try和catch块?

class ankit1    
{
public static void main(String args[])    
 {
        float a=20,b=120,c=50,sum;    
        sum=(a+b+c)/0;    
        System.out.println("The average of three number is:"+sum);    
    }      

 }  
Run Code Online (Sandbox Code Playgroud)

java exception-handling exception

2
推荐指数
1
解决办法
176
查看次数

标签 统计

exception ×2

java ×2

exception-handling ×1