3 ms·
> You can do that, but you need to do it for every exception type ): I'd love it if Java had templated exceptions. It does have them. You can write an interfac
by ossopite 6y ago
> You can do that, but you need to do it for every exception type ): I'd love it if Java had templated exceptions.
It does have them. You can write an interface with a type parameter `<E extends Throwable>` and declare functions inside it with `throws E`
- culturedsystems 6y agoYou can do this, but it's not ideal. A function can list multiple exceptions in its throws clause, which share no common type except Throwable, but this combination of exception types can't be represented by a single type parameter (except for the common base type). So in a lot of cases, you lose information about the specific exceptions your function can throw, which limits the value of using checked exceptions.