In my opinion, it’s too easy to have an Unhandled exception in spawn
while the rest of the program keeps chugging along. (I ran into this with a long-lived process, with a cleanup Fiber that died due to an unanticipated IO::Error
, resulting in consequences later due to that cleanup not running…) I’d generally like to have my program die if there’s an unanticipated and uncaught exception in any Fiber, not just the main one.
I’m proposing spawn!
which looks like this:
def spawn!(*args, &block)
spawn do
begin
block.call
rescue ex
STDERR.print "Unhandled exception in spawn!: "
ex.inspect_with_backtrace(STDERR)
STDERR.print "spawn!: Fatal. Dying..."
STDERR.flush
exit(1)
end
end
end
Alternatively, the docs might need to more loudly declare that every use of spawn
should probably have a catch-all rescue
block.