17
17
import org .truffleruby .Layouts ;
18
18
import org .truffleruby .RubyContext ;
19
19
import org .truffleruby .core .proc .ProcOperations ;
20
+ import org .truffleruby .language .control .ExitException ;
20
21
import org .truffleruby .language .control .RaiseException ;
21
22
22
23
import com .oracle .truffle .api .CompilerDirectives .TruffleBoundary ;
@@ -42,15 +43,15 @@ public void add(DynamicObject block, boolean always) {
42
43
}
43
44
44
45
public DynamicObject runAtExitHooks () {
45
- return runExitHooks (atExitHooks );
46
+ return runExitHooks (atExitHooks , "at_exit" );
46
47
}
47
48
48
49
public void runSystemExitHooks () {
49
- runExitHooks (systemExitHooks );
50
+ runExitHooks (systemExitHooks , "system at_exit" );
50
51
}
51
52
52
53
@ TruffleBoundary
53
- private DynamicObject runExitHooks (Deque <DynamicObject > stack ) {
54
+ private DynamicObject runExitHooks (Deque <DynamicObject > stack , String name ) {
54
55
DynamicObject lastException = null ;
55
56
56
57
while (true ) {
@@ -62,8 +63,12 @@ private DynamicObject runExitHooks(Deque<DynamicObject> stack) {
62
63
try {
63
64
ProcOperations .rootCall (block );
64
65
} catch (RaiseException e ) {
65
- lastException = handleAtExitException (context , e );
66
+ handleAtExitException (context , e .getException ());
67
+ lastException = e .getException ();
68
+ } catch (ExitException e ) {
69
+ throw e ;
66
70
} catch (Exception e ) {
71
+ System .err .println ("Unexpected internal exception in " + name + ":" );
67
72
e .printStackTrace ();
68
73
}
69
74
}
@@ -77,16 +82,14 @@ public List<DynamicObject> getHandlers() {
77
82
}
78
83
79
84
@ TruffleBoundary
80
- public static DynamicObject handleAtExitException (RubyContext context , RaiseException raiseException ) {
81
- final DynamicObject rubyException = raiseException .getException ();
85
+ public static void handleAtExitException (RubyContext context , DynamicObject rubyException ) {
82
86
DynamicObject logicalClass = Layouts .BASIC_OBJECT .getLogicalClass (rubyException );
83
87
if (logicalClass == context .getCoreLibrary ().systemExitClass ||
84
88
logicalClass == context .getCoreLibrary ().signalExceptionClass ) {
85
89
// Do not show the backtrace for these
86
90
} else {
87
91
context .getDefaultBacktraceFormatter ().printRubyExceptionOnEnvStderr ("" , rubyException );
88
92
}
89
- return rubyException ;
90
93
}
91
94
92
95
}
0 commit comments