@@ -328,20 +328,26 @@ private void threadMain(DynamicObject thread, Node currentNode, Supplier<Object>
328
328
// Handlers in the same order as in FiberManager
329
329
} catch (KillException e ) {
330
330
setThreadValue (context , thread , Nil .INSTANCE );
331
- } catch (ExitException e ) {
332
- rethrowOnMainThread (currentNode , e );
333
- setThreadValue (context , thread , Nil .INSTANCE );
334
331
} catch (RaiseException e ) {
335
332
setException (context , thread , e .getException (), currentNode );
336
333
} catch (DynamicReturnException e ) {
337
334
setException (context , thread , context .getCoreExceptions ().unexpectedReturn (currentNode ), currentNode );
335
+ } catch (ExitException e ) {
336
+ rethrowOnMainThread (currentNode , e );
337
+ setThreadValue (context , thread , Nil .INSTANCE );
338
+ } catch (Throwable e ) {
339
+ final String message = StringUtils
340
+ .format ("%s terminated with internal error:" , Thread .currentThread ().getName ());
341
+ final RuntimeException runtimeException = new RuntimeException (message , e );
342
+ rethrowOnMainThread (currentNode , runtimeException );
343
+ setThreadValue (context , thread , Nil .INSTANCE );
338
344
} finally {
339
345
assert Layouts .THREAD .getValue (thread ) != null || Layouts .THREAD .getException (thread ) != null ;
340
346
cleanup (thread , Thread .currentThread ());
341
347
}
342
348
}
343
349
344
- private void rethrowOnMainThread (Node currentNode , ExitException e ) {
350
+ private void rethrowOnMainThread (Node currentNode , RuntimeException e ) {
345
351
context .getSafepointManager ().pauseRubyThreadAndExecute (
346
352
getRootThread (),
347
353
currentNode ,
0 commit comments