by svieira · 2y ago · 0 comments
interface ThrowingRunnable<E extends Throwable> {
void run() throws E;
}
Instead, the best you could do is manual multiplication of interfaces: interface AThrowingRunnable {
void run() throws ExceptionA;
}
interface BThrowingRunnable {
void run() throws ExceptionB;
}
// ... snip thousands more ...
Or give up and erase all the type information by saying `throws Exception` or `throws Throwable`.Genericizing throws in particular was tried in Midori [2] and worked out really well (by report). In addition, several less-than-completely-obscure languages are starting to experiment with the algebra of effects in general (as opposed to error handling in particular). Pony [3], OCaml [4], and others are experimenting with bringing what Koka [5] (among others) to the masses.
[1]: https://www.artima.com/articles/the-trouble-with-checked-exc...
[2]: https://joeduffyblog.com/2016/02/07/the-error-model/
interface ThrowingRunnable<E extends Throwable> {
void run() throws E;
}
Only, hardly anybody writes it that way, so people forget that it's possible. Why don't people use exception polymorphism in that way? I am not sure, but I believe it would make code too verbose, since every function containing a virtual method call to something that might throw would have to be parameterized that way.