Dear fellow Ruby developers, please kick the habit of catching and rethrowing exceptions, thus ridding your users of the expeptions’ stack traces. Recently I had to patch the source code of an ActiveRecord adapter as well as the underlying DBI implementation in order to find out where one particular exception was originating from. This makes debugging code really a hassle. I haven’t had this kind of problem in Java since nested exceptions.
Tags: development, programming, ruby, wtf
What if we re-raise the same error we rescued?
begin
raise ‘foo!’
rescue => error
error.message.insert 0, “error when trying to do foo: ”
raise error
end
Then you won’t lose the original stack trace and you’ll get added information in the error message.