-4
在我的代碼,我的方法之一說:不知道如何處理的FileWriter異常
this.write("stuff")
和write方法是
public void write(String text) throws IOException
{
FileWriter writer = new FileWriter(path, true);
PrintWriter printer = new PrintWriter(writer);
printer.printf("%s" + "%n", text);
printer.close();
}
事情說有一個 "unreported exception java.io.IOException; must be caught or declared to be thrown"
爲FileWriter。
我應該在try和catch語句中修復異常?
你應該把你的電話給'this.write' try塊,趕在錯誤中提到的例外消息,然後優雅地對其進行處理。但是瞭解Java程序員,你可能只需要放入一個'printStackTrace'調用,而忘記其餘部分。 –
你說這個方法拋出一個異常,但是你不用try/catch塊來捕獲異常 – Li357
你需要處理異常。請參閱[捕獲和處理異常](https://docs.oracle.com/javase/tutorial/essential/exceptions/handling.html) – copeg