diff --git a/ext/tk/lib/tkafter.rb b/ext/tk/lib/tkafter.rb index be2e50ff3a..4876797c01 100644 --- a/ext/tk/lib/tkafter.rb +++ b/ext/tk/lib/tkafter.rb @@ -1,6 +1,6 @@ # # tkafter.rb : methods for Tcl/Tk after command -# 1998/07/02 by Hidetoshi Nagai +# 2000/08/01 by Hidetoshi Nagai # require 'tk' @@ -37,7 +37,16 @@ class TkAfter ############################### def do_callback(*args) @in_callback = true - ret = @current_proc.call(*args) + begin + ret = @current_proc.call(*args) + rescue StandardError, NameError + if @cancel_on_exception + cancel + return nil + else + fail $! + end + end if @set_next set_next_callback(*args) else @@ -118,6 +127,8 @@ class TkAfter @after_id = nil @after_script = nil + @cancel_on_exception = true + set_procs(*args) if args != [] @running = false @@ -135,7 +146,16 @@ class TkAfter end def current_status - [@running, @current_sleep, @current_proc, @current_args, @do_loop] + [@running, @current_sleep, @current_proc, @current_args, + @do_loop, @cancel_on_exception] + end + + def cancel_on_exception? + @cancel_on_exception + end + + def cancel_on_exception=(mode) + @cancel_on_exception = mode end def running? diff --git a/ext/tk/lib/tktext.rb b/ext/tk/lib/tktext.rb index 163583f139..f7b3f84ba7 100644 --- a/ext/tk/lib/tktext.rb +++ b/ext/tk/lib/tktext.rb @@ -460,7 +460,7 @@ class TkText