Exception Handling Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

What is the $! sign in Ruby?

A

It is a global constant in which Ruby assigns the last exception.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How should be the order when we have several rescue blocks?

A

Especific exception first and generic ones at the end.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly