Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jamalahmedmaaz/813151d17cbbfb5cdc600a16fe64c577 to your computer and use it in GitHub Desktop.
Save jamalahmedmaaz/813151d17cbbfb5cdc600a16fe64c577 to your computer and use it in GitHub Desktop.
5 Great Resources for Exception Handling Best Practices in Java

General Tip

"The trick is to catch exceptions at the proper layer, where your program can either meaningfully recover from the exception and continue without causing further errors, or provide the user with specific information, including instructions on how to recover from the error. When it is not practical for a method to do either of these, simply let the exception go so it can be caught later on and handled at the appropriate level."

Resources

Advantages of Exceptions
Excellent example of separating error-handling code from program logic

Three Rules for Effective Exception Handling
Longer explanation and case study of exception use, including the basic principles of "throw early" and "catch late". Clear and thorough.

Java Tutorials: Exceptions
A well-organized series of tutorials about what exceptions are and how to use them.

Exception Handling Antipatterns
Some precise examples of incorrect usage of exceptiosn (Scroll down to "Antipatterns").

Best Practices for Exception Management
Most of the above resources for found in this excellent Stack Overflow question.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment