4 ms·
I have never tried that, thanks! Does it work for a variable list of things, or would supporting two different checked exceptions require two generic params?
by Groxx 3y ago
I have never tried that, thanks!
Does it work for a variable list of things, or would supporting two different checked exceptions require two generic params? If it's one per param I think that's neat but probably limited in use to "your exception can contain a generic value", like `throw NewInsertFailedException(value)`.
- PhilipRoman 3y agoI think you might be able to trick the type checker to accept union types, but I'm not sure. I know intersection types are possible, but they are not really useful for exceptions. Regarding practicality - I've used this feature when implementing a visitor class API, so it definitely has some use cases. The biggest problem is that all it takes is a single method in the chain which does not support this pattern (think java.util.stream). For internal code it's pretty easy to decorate all functions that take callback lambdas, etc.