i have a call to a function foo(void)[]const u8 that is failing with a runtime panic… without changing the signature of foo to return an error union, is there a way to wrap my call to foo such that i can use catch to substitute some reasonable default return value such as ""…
or do i need to explicitly define an error-returning wrapper function that in turn calls foo internally??? or does this simply kick the can down the road…
the compiler fails with messages saying it expects an error union, regardless of what i’ve tried…
No, zig does not have a way to do that. (I believe on purpose)
You can store the registers (instruction pointer, stack pointer, etc) before entering foo and when the panic handler is called you can restore the registers.
I have done that in zig-recover.
If there is a C library with setjmp/longjmp this is it, if not you have to write it.
And some advice: don’t do it.
Find a way to fix the code in order to avoid the panic. Is it an arithmetic overflow? Is it a division by zero? Something else? There is always some way to fix it.
it was actually an assert that was failing inside some ZLS code i’ve forked/hacked… with the source available, i was able to see the low-level function’s assumption – and just call the function conditionally upon meeting this constraint…