Closed apatrida closed 9 years ago
Yes there is. When we change the interface to Throwable
we would also implicitly state that we handle any subclass of Error
. Besides catching Errors
is being considered an unrecommended practice it also doesn't make much sense in most cases. E.g. we can't really recover from an OutOfMemoryError
or other virtual machine Error
s. There is only one exception, as far as I know, and that is StackOverflowError
which we actually can recover from.
But to me it makes much more sense to actually let those Error
s crash the program as there needs to be something fixed in the user code (e.g. no unbounded recursion) or altered on the platform it's running on (e.g. more memory).
That being said, I purposely let the interface Promise<V, E>
and Deferred<V, E>
open for any use case you might have. So whether you want it to be Throwable
or something like String
that's possible. As an alternative to wrapping Throwable
s in Exception
s you could also write your own support methods like then
and async
. Wouldn't be much effort to create you own flavour as you can see by the current implementation
Yes, its not my choice, it is the other framework that has that in their async methods as the error type. (vert.x 3)
And the extension function then
uses things private within Kovenant...
I think it's best to stick to best practices for reasons described in my previous comment. As for the private functions of then
, it's only some extension functions reducing the clutter in the same file. Shouldn't be that of a problem to mimic it.
Is there a reason we can't have one for Throwable instead of just Exception? For example, Vert.x always types their exceptions callback handlers with Throwable, so would have to wrap every exception otherwise.