Exception Handling Flashcards
1
Q
What is the $! sign in Ruby?
A
It is a global constant in which Ruby assigns the last exception.
2
Q
How is the syntax of an exception?
A
begin
# code to be run
rescue => # there can be more than one rescue
# code to be run if an error occurs in the begin block
retry [Optional] # this will retry until the begin block doesn’t throw an error
else [Optional]
# code to be run if NO error occurs in the begin block
ensure [Optional]
# code to be run either way
end
3
Q
How should be the order when we have several rescue blocks?
A
Especific exception first and generic ones at the end.