From: Yukihiro Matsumoto Date: 2009-11-07T09:28:10+09:00 Subject: [ruby-core:26581] Re: [Bug #2343] Timeout.timeout doesn't raise Timeout::Error by default Hi, In message "Re: [ruby-core:26563] [Bug #2343] Timeout.timeout doesn't raise Timeout::Error by default" on Fri, 6 Nov 2009 21:00:28 +0900, Hongli Lai writes: |Timeout.timeout's documentation says that it'll raise Timeout::Error by default, but the code actually raises an object whose class is an anonymous subclass of Timeout::ExitException: | | def timeout(sec, klass = nil) | ... | exception = klass || Class.new(ExitException) | |This is not only inconsistent with the documentation, but also breaks many applications which assume that Timeout::Error is the default. | |So which one is wrong? The code or the documentation? If the documentation is wrong then what was the reason for the change? Both are right. It says: # Executes the method's block. If the block execution terminates before # +sec+ seconds has passed, it returns the result value of the block. # If not, it terminates the execution and raises +exception+ (which defaults # to Timeout::Error). So, it doesn't say anything that timeout would post that exception in to the block, but timeout itself would raise Timeout::Error. The reason of this behavior is the subclass of StandardError is too easily caught by default rescue. If you want to post specific exception into the block, specify the exception class as a second argument. I admit the documentation can be improved. Suggestion welcome. matz.