def process_widgets(widget)
return if widget == nil || !widget.is_a?(Widget)
#do my stuff here
end
Is it better to just let the function wipe out with an exception ?
Most of the time, if you are testing for gross programmation bugs, not
valid usage edge cases, just let it explode. The stacktrace will tell
where the function was incorrectly called.
If the error is hard to guess this way, or if it's an API or a
reusable library, then nicer error recovery/messages could be useful.
> def process_widgets(widget)
> return if widget == nil || !widget.is_a?(Widget)
>
> #do my stuff here
> end
> Is it better to just let the function wipe out with an exception ?
Most of the time, if you are testing for gross programmation bugs, not
valid usage edge cases, just let it explode. The stacktrace will tell
where the function was incorrectly called.
If the error is hard to guess this way, or if it's an API or a
reusable library, then nicer error recovery/messages could be useful.
Alain
Take a look at the 'verify' method. This is probably only useful for
common patterns. For example, I do this in some of my controllers..