Example of 'Exception Continuing Up The Stack'? [Answered]

Quote from book "Only Handle What You Can Fix: If an exception handler cannot resolve the problem represented by the exception, the handler should not exist. Instead, the exception should be allowed to continue up the call stack, hoping that something farther up has meaningful resolution steps for the problem. This is a counterpoint to the previous item. If there is no recourse for an error, it is reasonable for the program to end. There are some allowances here. Sometimes, a handler will repair or address what it can (even just logging the problem) while still allowing the exception to continue (described later)." I'm having a hard time conceptualizing when to use try catch because things break all over the place lol and how 'continuing up the stack' can resolve the issue.
17 Replies
toddlahakbar
toddlahakbar3y ago
Not sure I agree with the author because exceptions should be used for situations that the dev can't handle
BigggMoustache
BigggMoustacheOP3y ago
I thought they meant like, at runtime? or in debug or something?
toddlahakbar
toddlahakbar3y ago
If the dev can't know how to handle an exception, how is the code running supposed to?
BigggMoustache
BigggMoustacheOP3y ago
maybe I should copy more text to clarify
toddlahakbar
toddlahakbar3y ago
Oh, they include logging in the set of things that can resolve the problem
BigggMoustache
BigggMoustacheOP3y ago
what does it mean 'continuing up the stack' and how could that help?
toddlahakbar
toddlahakbar3y ago
I mean, a thrown exception , of not handled, bubbles up the call stack
BigggMoustache
BigggMoustacheOP3y ago
right but i don't understand how that'd resolve it
toddlahakbar
toddlahakbar3y ago
I don't either, is like the assumption is there's more information related to solving the problem in a method father up the call stack
BigggMoustache
BigggMoustacheOP3y ago
like if there were try in calling method and an exception for the type thrown in called method?
toddlahakbar
toddlahakbar3y ago
Sure. So exception in called, not handled in called, caller has a try catch and catches the exception ... how to resolve an exception is so specific to that exception that ... yeah that's an odd statement
BigggMoustache
BigggMoustacheOP3y ago
yeah man I can't make heads or tails of it. I try not to bug the author but I guess I'll just ask them lol
333fred
333fred3y ago
Resolve is a strong word And probably not the right one
toddlahakbar
toddlahakbar3y ago
That's my sticking point. Exceptions should be for things you can't handle
BigggMoustache
BigggMoustacheOP3y ago
okay that's helpful lol yeah it really confused the poop outta me
Mayor McCheese
Logging doesn't resolve the problem (opinion)
Accord
Accord3y ago
✅ This post has been marked as answered!
Want results from more Discord servers?
Add your server