2 ms·
Not a bad article overall but I wish the author had spent some time talking about error and exception handling. At some point code you’ve written is going be c
by JackFr 5y ago
Not a bad article overall but I wish the author had spent some time talking about error and exception handling.
At some point code you’ve written is going be called by the framework and throw an exception. Recovery is often more difficult or not possible because you don’t have much knowledge of the calling frame. Are any of these approaches better or worse suited, or do they have any special requirements?
I’m thinking of among other things Java Runnables throwing exceptions and silently killing threads.
- BulgarianIdiot 5y agoI don't think there's anything specific to frameworks about exception handling. You're not supposed to throw exceptions the caller doesn't expect. What does it expect? Well it expects what's documented on the type is takes (either as checked exceptions, or by convention if that's not part of the language). And any other unexpected errors should be of an appropriate type (Error in Java for ex.) where the framework will finalize its resource handles, and rethrow to some global handler either you or the framework defines. At which point it's in your hand. And if your exception doesn't fit such a scenario, then probably it shouldn't have been thrown to the framework's stack frames in the first place.