5 ms·
I thought extending _throws_ with an _as_ clause would make it far more manageable: void foobar() rethrows IOException as AppException rethrows FooError, Ba
by ben509 7y ago
I thought extending _throws_ with an _as_ clause would make it far more manageable:
void foobar() rethrows IOException as AppException rethrows FooError, BarError as WtfError {
Being able to express that a bunch of internal exceptions should be wrapped in an application exception would save a ton of boilerplate.
The exception syntax itself is also clunky. If you have a complex expression, you have to extract it and assign it to a variable. But you still have to declare that variable outside the try/catch. And, of course, every exception requires Yet Another Class Definition. I'd do:
class SomeClass {
exception ThingBroke handles ArithmeticException;
exception DatabaseDown handles SQLException;
void method(int a) {
try {
int x = (555 / a rethrows ThingBroke) + (getNum() rethrows DbDown);
} catch(ThingBroke e) {
I think the other issue is the separate hierarchy for unchecked exceptions. In theory, they were supposed to be issues you couldn't recover from, thus the correct response was to let the caller fail. But now UncheckedIOException is not a subclass of IOException.
Maybe a better approach would be to add an Unchecked interface, though from my reading of the source for exceptions, they seem to be very brittle and maybe there's just no fixing it.
- wvenable 7y ago> Being able to express that a bunch of internal exceptions should be wrapped in an application exception would save a ton of boilerplate. It would but I think it's the wrong approach -- you're actively changing the error information that really provides no additional value except to make the type-checker happy because the alternative is too verbose.
- asplake 7y agoDoesn’t wrapping usually mean adding (semantic) information without changing the original?
- wvenable 7y agoYou no longer propagating the same error; if you were type-checking on network exceptions, for example, you would entirely miss it if it was wrapped in LibraryException instead. Wrapping does have value if you are really adding useful information but the example here is just changing the type which really doesn't add anything useful.