From: "NAKAMURA, Hiroshi" Date: 2002-12-03T19:47:06+09:00 Subject: Re: inwoking irb from the middle of things Hi, > From: "Radek Hnilica" > Sent: Friday, November 29, 2002 9:18 PM > The far goal is to have fully interactive environment where in time of > failure the program doesn't end but fires interactive session. $ cat catch.rb require 'irb' module IRB def IRB.start2(eval_binding, ap_path) IRB.setup(ap_path) irb = Irb.new(WorkSpace.new(eval_binding)) @CONF[:MAIN_CONTEXT] = irb.context trap("SIGINT") do irb.signal_handle end catch(:IRB_EXIT) do irb.eval_input end end end set_trace_func proc { |event, file, line, id, binding, *rest| if event == 'raise' $stdout.printf "%s:%d: `%s' (%s)\n", file, line, $!, $!.class tb = caller(0)[2..-1] for i in tb $stdout.printf "\tfrom %s\n", i end IRB.start2(binding, $stdin) end } $ ruby17 -rcatch -e 'a = 5; raise rescue RuntimeError; p a' You can catch an exception and inspect a binding where an error occurred. But... after quitting IRB session, your program will exit silently. e.g. "p a" above won't executed. Hmm. Doing catch/throw when "raise" before "rescue" might let ruby confuse though I don't know anything about it. Back to the topic, as ts stated, debug.rb could help you. $ ruby -rdebug -e 'a = 5; raise rescue RuntimeError; p a' Debug.rb Emacs support available. -e:1:a = 5; raise rescue RuntimeError; p a (rdb:1) cont -e:1: `' (RuntimeError) from -e:1 -e:1:a = 5; raise rescue RuntimeError; p a (rdb:1) a = 6 6 (rdb:1) cont 6 Bear in mind you cannot recover(resume) the exception to continue execution. We don't have standard way to do it. Regards, // NaHi