Search code examples
exceptioncrystal-lang

Is there a way to exit the process if any Fiber encounters an exception?


Right now I have a couple of fibers with loops:

spawn {
  begin
    loop { }
  rescue e : MyType
  end
}

I'm using begin/rescue in them to catch exceptions, print a message, and exit the process. Is there a way to specify only once to catch any exception throughout the running program instead of using begin/rescue repeatedly in each different fiber?


Solution

  • No. Any unhandeled exception inside a fiber is rescued and printed to stderr. If you need to do something else, you'll have to catch the exception inside the fiber body.