我试图编译这段代码,但它一直有一个错误,JAVA。我得到一个“未报告的异常”编译器错误
errThrower.java:37: error: unreported exception Exception; must be caught or declared to be thrown
throw new Exception();
,抛出此异常在callmethodErr()
,而且我认为这已经被抓主要的,但我无法弄清楚发生了什么。
谢谢大家。
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()'尚未与所定义的方法'抛出Exception',但它确实。这当然很明显? – EJP
请让我提醒你,如果有人帮助你,接受答案是礼貌的。 – Stewart