When a stack overflows, the system performs a throw/1 with an appropriate exit tag, i.e.,
These exits can be caught by wrapping a goal that is likely to overflow the stacks into an appropriate catch/3, e.g.,
..., catch(big_goal(X), global_trail_overflow, react_to_overflow), ...
In the debugger, you can locate the overflow by jumping to a LEAVE port (z command). See chapter 19 for more details on memory usage.