2009-02-07 5 views

답변

16

스레드 클래스 'abort_on_exception 플래그를 true로 설정하십시오.

대신에 throw/catch 블록에서 스레드 본문을 래핑하고 catch에 예외를 덤프하십시오.

6

명시 적으로 처리하지 않은 오류를 잡아서 STDOUT으로 인쇄해야합니다.

require 'pp' 

Thread.new { 
    begin 
    a = 1/0 
    rescue 
    pp $! 
    end 
} 

결과 : #<ZeroDivisionError: divided by 0>

8

true로 $DEBUG 설정 (당신이 -d 사용하여 명령 줄에서이 작업을 수행 할 수 있습니다), 당신은

ruby -d bad_thread.rb 
Exception `LoadError' at /usr/lib/ruby/site_ruby/1.8/rubygems.rb:1113 - no such file to load -- rubygems/defaults/operating_system 
Exception `LoadError' at /usr/lib/ruby/site_ruby/1.8/rubygems/config_file.rb:34 - no such file to load -- Win32API 
Exception `ZeroDivisionError' at bad_thread.rb:2 - divided by 0 
bad_thread.rb:2:in `/': divided by 0 (ZeroDivisionError) 
    from bad_thread.rb:2 
    from bad_thread.rb:1:in `initialize' 
    from bad_thread.rb:1:in `new' 
    from bad_thread.rb:1 
+1

감사합니다거야! 이로 인해 문제가되는 DRb 서버의 디버깅 속도가 엄청나게 빨라졌습니다. – Phrogz

관련 문제