【发布时间】:2017-06-12 11:12:19
【问题描述】:
我正在尝试编译这段代码,但一直出错,
errThrower.java:37: error: unreported exception Exception; must be caught or declared to be thrown
throw new Exception();
这个异常是在callmethodErr()中抛出的,我还以为是在main中被抓到了,但是不知道是怎么回事。
谢谢大家。
import java.util.IllegalFormatConversionException;
public class errThrower
{
public static void main(String[] args)
{
try
{
callmethodErr();
}
catch (Exception e)
{
e.printStackTrace();
}
}
public static void methodErr() throws Exception
{
System.out.println("error thrown from methodErr");
}
public static void callmethodErr()
{
try
{
methodErr();
}
catch (Exception e)
{
System.out.println("error thrown from callMethodErr");
throw new Exception();
}
}
}
【问题讨论】:
-
callmethodErr()尚未使用throws Exception定义,但它确实如此。这肯定很明显吗? -
请我提醒您,如果有人帮助了您,接受答案是有礼貌的..
标签: java exception checked-exceptions catch-exception