|
8) avoid empty catch blocks.
Nothing is worse than an empty catch block, because it not only hides errors and exceptions, but also may cause your object to be unavailable or dirty. Empty catch blocks can only become meaningless. If you are very certain that exceptions will not continue to affect the object state in any way, but during program execution, logging errors is still the best (method ). Writing Exception Handling Code in Java programming is not only a Java best practice, but also the most common practice.
9) usage standard exception
We recommend that you use standard and built-in JAVA exceptions in Article 9 best practices. We use standard exceptions instead of creating our own exceptions each time. It is the best choice for maintainability and consistency, both now and in the future. The reuse of standard exceptions makes the code more readable, because most Java developers have standard exceptions such as JDK runtimeexception, illegalstateexception, illegalargumentexception, or nullpointerexception. (developer) they can understand the purpose of each type of exception at a glance, rather than looking for the purpose of a user-defined exception in code or in the document.
10) record exceptions thrown by any method
Java provides the throw and throws keywords to throw exceptions. In javadoc, @ throw is used to record exceptions that may be thrown by any method. If you write APIs or public interfaces, this becomes very important. Exceptions thrown by any method are recorded in the relevant documents, so that you can subconsciously remind anyone who uses this method.
These are all the best practices to be followed when handling exceptions in Java programming. Let us know what practices should be followed when writing Exception Handling Code in Java programming.
From: http://www.oschina.net/translate/10-exception-handling-best-practices-in-java-programming? From = 20130407
|