Ruby has two different exceptions mechanisms: Throw/Catch and Raise/Rescue.
Why do we have two?
When should you use one and not the other?
exceptionruby
Ruby has two different exceptions mechanisms: Throw/Catch and Raise/Rescue.
Why do we have two?
When should you use one and not the other?
Best Solution
raise
,fail
,rescue
, andensure
handle errors, also known as exceptionsthrow
andcatch
are control flowTerminating a single level of control flow, like a
while
loop, can be done with a simplereturn
. Terminating many levels of control flow, like a nested loop, can be done withthrow
.References