I think Durian's Errors class combines many of the pros of the various suggestions above.
- Wrap a throwing function to a standard Java 8 functional interface.
- Easily specify various policies for handling errors
- When wrapping a method that returns a value, there is an important distinction between specifying a default value or rethrowing a RuntimeException.
- Throwing versions of Java 8's functional interfaces
- Standard interfaces for throwing specific exceptions
- Which addresses Zoltán's concern
To include Durian in your project, you can either:
- grab it from jcenter or maven central at
com.diffplug.durian:durian:3.3.0
- or just copy paste just two small classes into your code: Throwing.java and Errors.java