All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.sonar.l10n.squidjava.rules.squid.S1141.html Maven / Gradle / Ivy

Nesting try-catch blocks severely impacts the readability of source code because it makes it to difficult to understand which block will catch which exception.

The following code:

try {
  try {                                     // Non-Compliant
    doSomething();
  } catch (RuntimeException e) {
    /* Ignore */
  }

  doSomethingElse();
} catch (Exception e) {
  /* ... */
}

should be refactored into:

try {
  dedicatedMethod();                        // Compliant
  doSomethingElse();
} catch (Exception e) {
  /* ... */
}

/* ... */

private void dedicatedMethod() {
  try {                                     // Compliant
    doSomething();
  } catch (RuntimeException e) {
    /* Ignore */
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy