为什么不打印此例外?为什么会出现错误? [英] Why is this exception is not printed? Why it's showing an error?
本文介绍了为什么不打印此例外?为什么会出现错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果我试图打印a的值,为什么显示错误?为什么异常会成为错误?
If I am trying to print value of "a" why is it showing error? Why has the exception become an error?
class Ankit1
{
public static void main(String args[])
{
float d,a;
try
{
d=0;
a=44/d;
System.out.print("Its not gonna printed"+a); //if Exception not occurs then it will print and it will ot goto catch block
}
catch(ArithmeticException e)
{
System.out.println("Print hoga"+a);//why error come??
}
}
}
推荐答案
如果看到错误
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
The local variable a may not have been initialized
at your.package.Ankit1.main(Ankit1.java:18)
明确说明本地变量a可能尚未初始化
您收到此错误,因为您的变量 a
未初始化。
You're getting this error as your variable a
wasn't initialized.
如果您想要打印错误消息尝试打印... e.getMessage()
或 p.printStackTrace()
表示完整堆栈跟踪。
And if you want to print the error message try printing... e.getMessage()
or p.printStackTrace()
for complete stack trace.
要修复这个简单的初始化 a
,其中包含一些这样的值......
To fix this simple initialize a
with some value like this...
float a = 0;
这篇关于为什么不打印此例外?为什么会出现错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文