• 締切済み

エラー処理について

現在コーディング中で、バグが発生しないよう例外処理を きちっとしておきたいと思い、例外処理に関して参考になる 書籍・Webページを探しています。 オススメの書籍等ありましたら、紹介をお願います。

みんなの回答

  • ninoue
  • ベストアンサー率52% (1288/2437)
回答No.2

#1 です。 うっかりしてJavaの事についての回答をしてしまい、すみませんでした。 同じサイトにC++の本もありますので参考になるのではと思います。 (ただし、中身はほとんど読んでいません) http://mindview.net/Books/TICPP/ThinkingInCPP2e.html Thinking in C++ 2nd Edition by Bruce Eckel Free Electronic Book Volume 1 & Volume 2

  • ninoue
  • ベストアンサー率52% (1288/2437)
回答No.1

次の本の Chapt.9: Error Handling with Exceptionsにかなり詳細な検討、コーディング例等が示されていますので参考になるのではと思われます。 http://www.mindview.net/Books/TIJ/ Free Electronic Book: Thinking in Java, 3rd Edition Exception guidelines Use exceptions to: 1. Handle problems at the appropriate level. (Avoid catching exceptions unless you know what to do with them). 2. Fix the problem and call the method that caused the exception again. 3. Patch things up and continue without retrying the method. 4. Calculate some alternative result instead of what the method was supposed to produce. 5. Do whatever you can in the current context and rethrow the same exception to a higher context. 6. Do whatever you can in the current context and throw a different exception to a higher context. 7. Terminate the program. 8. Simplify. (If your exception scheme makes things more complicated, then it is painful and annoying to use.) 9. Make your library and program safer. (This is a short-term investment for debugging, and a long-term investment for application robustness.) Summary Improved error recovery is one of the most powerful ways that you can increase the robustness of your code. Error recovery is a fundamental concern for every program you write, but it’s especially important in Java, where one of the primary goals is to create program components for others to use. To create a robust system, each component must be robust. By providing a consistent error-reporting model with exceptions, Java allows components to reliably communicate problems to client code. The goals for exception handling in Java are to simplify the creation of large, reliable programs using less code than currently possible, and to do so with more confidence that your application doesn’t have an unhandled error. Exceptions are not terribly difficult to learn, and are one of those features that provide immediate and significant benefits to your project.

関連するQ&A