Given the fact that
A=Any push!(A,A) hash(A) ERROR: StackOverflowError:
I thought it a nice exercise to try to handle recursive data structures. Since most use-cases are not recursive, let’s try to do this with an exception (try-catch should be cheap, right?). First, can I catch StackOverflow?
function recurse_(n) try return recurse_(n+1) catch x return x end end dump(recurse_(0)) StackOverflowError StackOverflowError()
Ok, nice. Unfortunately, rethrowing is not help-full; I need to investigate the stacktrace in order to see how far to unwind. For a little debug purpose:
function recurse2_(n) try return recurse2_(n+1) catch x println(n) return x end end recurse2_(0) Segmentation fault (core dumped)
Hmm, not sure that I intended that (what I did hope for is that the innermost println throws again, I go up in the stack until the println succeeds and afterwards I return normally – and this was supposed to work regardless how deep println goes— the printed n should be recursion depth minus stack space needed for println).
So examining the stacktrace is probably impossible if I am sitting at the bottom of the recursion limit?
Is there a reasonable try-catch construction for “unwind until the topmost occurence of this instruction pointer, skipping catch handlers in between”? Is there a reasonable way of seeing exception handlers above me in the stack, if I had a stacktrace/backtrace and was not at the limit?
(sorry for the possible notational confusion; for the purposes of this post, the stack grows from top to bottom, intel-style)