Index: src/org/jruby/RubyThread.java =================================================================== --- src/org/jruby/RubyThread.java (revision 4781) +++ src/org/jruby/RubyThread.java (working copy) @@ -267,7 +267,7 @@ } } - private RubyThread(Ruby runtime, RubyClass type) { + protected RubyThread(Ruby runtime, RubyClass type) { super(runtime, type); this.threadService = runtime.getThreadService(); // set to default thread group @@ -682,14 +682,16 @@ public void exceptionRaised(RaiseException exception) { assert isCurrent(); - Ruby runtime = exception.getException().getRuntime(); - if (abortOnException(runtime)) { + RubyException rubyException = exception.getException(); + Ruby runtime = rubyException.getRuntime(); + if (rubyException.getMetaClass() == runtime.getClass("SystemExit")) { + threadService.getMainThread().raise(new IRubyObject[] {rubyException}, Block.NULL_BLOCK); + } else if (abortOnException(runtime)) { // FIXME: printError explodes on some nullpointer //getRuntime().getRuntime().printError(exception.getException()); - // TODO: Doesn't SystemExit have its own method to make this less wordy.. - RubyException re = RubyException.newException(getRuntime(), getRuntime().getClass("SystemExit"), exception.getMessage()); - re.setInstanceVariable("status", getRuntime().newFixnum(1)); - threadService.getMainThread().raise(new IRubyObject[]{re}, Block.NULL_BLOCK); + RubyException systemExit = RubySystemExit.newInstance(runtime, 1); + systemExit.message = rubyException.message; + threadService.getMainThread().raise(new IRubyObject[] {systemExit}, Block.NULL_BLOCK); return; } else if (runtime.getDebug().isTrue()) { runtime.printError(exception.getException()); Index: src/org/jruby/Ruby.java =================================================================== --- src/org/jruby/Ruby.java (revision 4781) +++ src/org/jruby/Ruby.java (working copy) @@ -1703,9 +1703,7 @@ } public RaiseException newSystemExit(int status) { - RubyClass exc = getClass("SystemExit"); - IRubyObject[]exArgs = new IRubyObject[]{newFixnum(status), newString("exit")}; - return new RaiseException((RubyException)exc.newInstance(exArgs, Block.NULL_BLOCK)); + return new RaiseException(RubySystemExit.newInstance(this, status)); } public RaiseException newIOError(String message) { Index: src/org/jruby/RubySystemExit.java =================================================================== --- src/org/jruby/RubySystemExit.java (revision 4781) +++ src/org/jruby/RubySystemExit.java (working copy) @@ -51,6 +51,14 @@ return systemExitClass; } + public static RubySystemExit newInstance(Ruby runtime, int status) { + RubyClass exc = runtime.getClass("SystemExit"); + IRubyObject[] exArgs = new IRubyObject[] { + runtime.newFixnum(status), + runtime.newString("exit") }; + return (RubySystemExit) exc.newInstance(exArgs, Block.NULL_BLOCK); + } + protected RubySystemExit(Ruby runtime, RubyClass exceptionClass) { super(runtime, exceptionClass); status = runtime.getNil(); @@ -78,4 +86,4 @@ return getRuntime().getFalse(); } -} \ No newline at end of file +}