This tip from Roman describes the common exceptions catching bad practice, which everyone should be aware of and avoid. When writing
begin
...
rescue Exception => e
...
endyou will catch all errors, including SyntaxError. This may be a real problem, and the broken code will run until some customer reports it. The example two files illustrate it:
bad_file.rb:
()(())
test.rb:
begin
require 'bad_file'
rescue Exception => e
puts "In rescue 1."
end
begin
require 'bad_file'
rescue => e
puts "In rescue 2."
endWhen running test.rb, it prints:
In rescue 1.
test.rb:8:in `require': ./bad_file.rb:1: syntax error, unexpected '(', expecting $end (SyntaxError)
()(())
^
from test.rb:8which proves that 'rescue Exception => e' style is dangerous and catches the error you would not want to be in the code.