M
matt neuburg
It came as a big surprise to me when I discovered that this code:
begin
# do stuff
rescue
# do rescue stuff
end
....could fail to catch exceptions thrown in the "do stuff" section. A
bare "rescue" looks to me like it ought to mean: catch every exception.
Instead it turns out to mean: catch a certain subset of exceptions. It
doesn't catch LoadError, it doesn't catch SyntaxError, etc. etc.
Of course now I know better (and I commonly write "rescue Exception"),
but it still feels wrong, especially in view of the "principle of least
surprise". And I see by a quick Google search that people regard this as
an annoying "gotcha". Is it worth proposing an actual change in the
language - that the default rescue be Exception instead of
StandardError? m.
begin
# do stuff
rescue
# do rescue stuff
end
....could fail to catch exceptions thrown in the "do stuff" section. A
bare "rescue" looks to me like it ought to mean: catch every exception.
Instead it turns out to mean: catch a certain subset of exceptions. It
doesn't catch LoadError, it doesn't catch SyntaxError, etc. etc.
Of course now I know better (and I commonly write "rescue Exception"),
but it still feels wrong, especially in view of the "principle of least
surprise". And I see by a quick Google search that people regard this as
an annoying "gotcha". Is it worth proposing an actual change in the
language - that the default rescue be Exception instead of
StandardError? m.