This page contains temporary result from dicussions on error handling.

These guidelines must be reviewed and approved before being promoted to the Error Handling page.

Best practices

Anti patterns

Re-wrapping exceptions

Not correct propagation :

try {
  // do risky stuff
} catch (Exception e) {
  throw new RuntimeException(e); // unnecessary wrapping in case if e instanceof RuntimeException
}

Better :

try {
  doRiskyStuff();
} catch (RuntimeException e) {
  throw e;
} catch (Exception e) {
  throw new RuntimeException(e.getMessage(), e);
}

With Google Guava :

try {
  // do risky stuff
} catch (Exception e) {
  throw Throwables.propagate(e);
}

Logback advanced features

Integration tests