我試圖編譯這段代碼,但它一直有一個錯誤,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