Home  >  Article  >  Java  >  How to log all exceptions thrown by a method in Java?

How to log all exceptions thrown by a method in Java?

PHPz
PHPzforward
2023-04-23 12:19:07931browse

Log all exceptions thrown by each method

This is seriously underused. Most public APIs don't have @throws Java documentation to explain the exceptions thrown.

This is a good example.

...
 *
 * @throws MalformedURLException The formal system identifier of a
 * subordinate catalog cannot be turned into a valid URL.
 * @throws IOException Error reading subordinate catalog file.
 */
public String resolveSystem(String systemId)
  throws MalformedURLException, IOException {
...

This is a bad example of a lack of information about under what circumstances an exception is thrown.

 * @throws Exception exception
 */
public void startServer() throws Exception {
    if (!externalDatabaseHost) {

The above is the detailed content of How to log all exceptions thrown by a method in Java?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:yisu.com. If there is any infringement, please contact admin@php.cn delete