Aborting/terminating script execution

Hi,

I’m attempting to write a visual Ruby debugger in a Java applet. As part
of this process, I’m installing my own event handler. I’ve been poking
around jruby-debug and the main interpreter loop in JRuby but can’t seem
to discover a way to abort execution (i.e., break out of the event
handler and execute no further instructions).

I thought that throwing a ThreadKill exception would suffice. From
within the event handler:

context.getThread().kill();

The problem is, this seems to get caught somewhere inside of JRuby.
Elsewhere in my code, I have:

// Install event hook and transfer control to it
jRubyRuntime.addEventHook(this);
try
{
jRubyContainer.runScriptlet(script); // eventHandler() will
now handle the message queue
}
catch (ThreadKill e)
{
System.out.printf(“VM #%d aborted trace\n”, id);
}

The exception is never caught. A stack trace is printed. Is there a safe
way of doing this?

It would also be nice to be able to halt a script externally (to
implement timeouts, for example). I’m aware of RubyThread.stop() but it
seems like this is intended to halt RubyThreads and is for internal use,
not for an external application embedding JRuby.

Thank you!

– Bart

P.S. Re: my other post concerning AccessControl violations within an
applet, I’ve found a temporary workaround and have filed a bug report as
requested.

I just realized that ThreadKill is caught internally by the interpreter.
What I’ve done instead is create a RubySystemExit exception and I throw
that. This causes a few more steps to be run (but that’s not a big
deal). I’m assuming this is the preferred way to break out of JRuby?

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs