A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/pmd/pmd/issues/955 below:

[java] Detect identical catch statements · Issue #955 · pmd/pmd · GitHub

Under Java 7 and later, it's possible to use multi-catch. We should have a rule detect such cases to help people migrate / reduce boilerplate.

Example:

try {
  // do something
} catch (ClassNotFoundException e) {
  if (LOG.isLoggable(Level.FINE)) {
    LOG.log(Level.FINE, "Could not find class " + className + ", due to: " + e);
  }
} catch (NoClassDefFoundError e) {
  if (LOG.isLoggable(Level.FINE)) {
    LOG.log(Level.FINE, "Could not find class " + className + ", due to: " + e);
  }
}

can be reduced to:

try {
  // do something
} catch (ClassNotFoundException | NoClassDefFoundError e) {
  if (LOG.isLoggable(Level.FINE)) {
    LOG.log(Level.FINE, "Could not find class " + className + ", due to: " + e);
  }
}

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4