-4
Q
は私のコードでは
A
答えて
0
Java開発には、あらゆる種類の例外を処理する方法が不可欠です。 それを行うには、2つの方法があります:
public void write(String text) //notice I deleted the throw
{
try{
FileWriter writer = new FileWriter(path, true);
PrintWriter printer = new PrintWriter(writer);
printer.printf("%s" + "%n", text);
printer.close();
catch(IOException ioe){
//you write here code if an ioexcepion happens. You can leave it empty if you want
}
}
と...は
public void write(String text) throws IOException //See here it says throws IOException. You must then handle the exception when calling the method
{
FileWriter writer = new FileWriter(path, true);
PrintWriter printer = new PrintWriter(writer);
printer.printf("%s" + "%n", text);
printer.close();
}
//like this:
public static void main(String[] args) //or wherever you are calling write from
{
try{
write("hello"); //this call can throw an exception which must be caught somewhere
}catch(IOException ioe){/*whatever*/}
}
あなたは、tryブロックでthis.write` `にあなたの電話を入れて、それは誤りで述べた例外をキャッチする必要があり
関連する問題
- 1. は私のコードで
- 2. 私は私のコード
- 3. 私のコードでは倍の
- 4. 私のPythonコードはRコード
- 5. android.widget.TableRowは私のコードでandroid.widget.TextView
- 6. は私のコードです
- 7. 私のコードではgcc
- 8. それは私のコードで
- 9. 私のコードでは、インサート
- 10. TypedQueryは私のコードでブロック
- 11. は、私は私のコードのjQuery
- 12. は、これは私のコードですAngular.js
- 13. は、これは私のコードです
- 14. .stopは()これは私のコードでホバーセレクター
- 15. は、これは私のコードです。#
- 16. キーは、これは私のコードです
- 17. は私のコードJS
- 18. 私のAHKコードは
- 19. は私のPythonコード
- 20. CSS3は私のコード
- 21. は私のコードJMockit
- 22. 私はこのコード
- 23. VBのコードは、これは私のVBAコードです〜40kのデータセット
- 24. は私のPHPコードでは、私はここで何をしようとしている私のPHPコード
- 25. が、私はコード
- 26. 私はVBAコード
- 27. は、これは私のコードの私の一部ですNSArrayの「
- 28. は、私は私のSPでこのコードを持ってsp_executesqlを
- 29. は、私は私のコントローラで次のコードを持って.to_i
- 30. 検証は、私は私のXAMLで、次のコード持って
メッセージを適切に処理します。しかし、Javaプログラマを知っているならば、たぶん 'printStackTrace'コールを入れて残りのことを忘れてしまうでしょう。 –
メソッドは例外をスローしますが、try/catchブロックを使用して例外をキャッチしないとします。 – Li357
例外を処理する必要があります。 [例外のキャッチと処理](https://docs.oracle.com/javase/tutorial/essential/exceptions/handling.html)を参照してください。 – copeg