#ScriptSaturday with enough alias magic, bash can have real try-catch syntax!

libsh module here; BSD-3 :)

@domi wait, but it only actually catches if you wrap it in a subshell, otherwise it just exits the whole shell after executing the catch and finally blocks?
@wolf480pl sorry i copied the wrong snippet, it’s fixed now

@domi oh, ok.

hmm... wouldn't it make more sense to set the trap inside the subshell?

@wolf480pl required some fiddling, but done! I could move essentially everything into that subshell, but i’m gonna leave out the other functions for now for slightly better readability

@domi does that mean one can now

try (
try (
return 1
) catch (
echo catch 1
) yrt
) catch (
echo catch 2
) yrt

?

@wolf480pl jesus christ

wrong braces, but. maybe? i’m gonna check

@domi wrong braces on purpose, otherwise I'm gonna redefine _catch :(

@wolf480pl okay, nesting is broken. i tried restructuring more stuff into the subshell and it “works” but some catches get redefined as the generic one

i’ll work on it more tomorrow :)

@domi actually, my example is stupid because the correct behaviour is only "catch 1" and it's indistinguishable from the outer catch getting overwritten. I should've used finally.
@domi oh and to be clear: I'm not likely to actually use this, I'm just nerdsniping you :P
@domi i do think it's cool tho

@wolf480pl the horrifying part is that this provides enough utility that I may want to use it! and this only started as a “what if?” :D

nerdsnipes are appreciated. i don’t have anyone else do code review, so this is nice