|
|
|
|
|
by zamalek
1819 days ago
|
|
> Why can't stack overflow be treated just like any other exception[...]? Consider the following code: func overflows() {
defer a()
fmt.Println("hello") // <-- stack overflow occurs within
}
func a() {
fmt.Println("hello")
}
The answer lies in trying to figure out how Go would successfully unwind that stack, it can't: when it calls `a` it will simply overflow again. Something that has been discussed is "StackAboutToOverflowException", but that only kicks the bucket down the road (unwinding could still cause an overflow).In truth, the problem exists because of implicit calls at the end of methods interacting with stack overflows, whether that's because of defer-like functionality, structured exception handling, or deconstructors. |
|
Perhaps one difference is that, while panics are always avoidable in a recovery function, stack overflows are not (if it happens to be deep enough already). Does the argument go “even a seemingly safe recovery function can’t be guaranteed to succeed, so prevent the illusion of safety”?
(To be clear: I’m not arguing, just trying to understand.)