I use rescue
for everything, not just for "rescuing" exceptions. I mean, I just love the way it spares me verification and double checking data.
By example, lets say I have a model Item
what may or may not have a User
. Then, when I want to get the owner's name of the item I write:
item.user.name rescue ""
instead of something like
item.user.nil? ? "" : item.user.name
It makes the same think, since nil.name
trigger an exception that I rescue with ""
, but I'm not pretty sure this is good practice. It makes what I want to, and it makes it with less code, but... I don't know, all that rescue
words here and there makes me feel insecure.
Is it a bad practice or is it valid abusing of the rescue
keyword?