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
Not sure I agree with the author because exceptions should be used for situations that the dev can't handle
I thought they meant like, at runtime?
or in debug or something?
If the dev can't know how to handle an exception, how is the code running supposed to?
maybe I should copy more text to clarify
Oh, they include logging in the set of things that can resolve the problem
what does it mean 'continuing up the stack' and how could that help?
I mean, a thrown exception , of not handled, bubbles up the call stack
right
but i don't understand how that'd resolve it
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
like if there were try in calling method and an exception for the type thrown in called method?
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
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
Resolve is a strong word
And probably not the right one
That's my sticking point. Exceptions should be for things you can't handle
okay that's helpful lol
yeah it really confused the poop outta me
Logging doesn't resolve the problem (opinion)
✅ This post has been marked as answered!