Skip to content

Instantly share code, notes, and snippets.

@raineorshine
Last active March 13, 2023 02:54
Show Gist options
  • Star 21 You must be signed in to star a gist
  • Fork 9 You must be signed in to fork a gist
  • Save raineorshine/5521119 to your computer and use it in GitHub Desktop.
Save raineorshine/5521119 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 exceptions.

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

@amitvirtex
Copy link

Three Rules for Effective Exception Handling : https://community.oracle.com/docs/DOC-983219
Exception Handling Antipatterns : https://community.oracle.com/docs/DOC-983543

@WegnerDan
Copy link

Three Rules for Effective Exception Handling : https://community.oracle.com/docs/DOC-983219 Exception Handling Antipatterns : https://community.oracle.com/docs/DOC-983543

grafik

Can't access those links.

@raineorshine
Copy link
Author

I have updated the originals. Thanks!

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