Java Exception Handling

From MPDLMediaWiki
Jump to navigation Jump to search

Problem description

Modules need dependencies of other modules only because of their exception classes

Stacktraces are sometimes swallowed

Sometimes, excessive stacktraces are shown, even without useful information

Logger.error, System.out and e.printStackTrace are mixed up happily

No distinction between exceptions and errors

Conclusion

Distinguish between errors and exceptions

Inside a module, always throw errors up as they are

When catching exceptions, log appropriately

Between modules, throw only generic exceptions (e.g. java.lang.Exception, java.lang.RuntimeException) without cause