Ruby Exception Handling MCQ
This section focuses on "Exception Handling" MCQs in Ruby. These Multiple Choice Questions (mcq) should be practiced to improve the Ruby skills required for various interviews (campus interviews, walk-in interviews, company interviews), placements, entrance exams and other competitive examinations.
1. In ruby, Exception handling is a process which describes a way to handle the __________.
View Answer
2. Which statement is used to execute the rescue block again from the beginning after capturing the exception?
View Answer
3. What will be output for the following code?
begin
raise 'Exception Created!'
puts 'After Exception'
rescue
puts 'Finally Saved!'
retry
end
View Answer
4. Raise Statement is used for?
View Answer
5. What will be output for the following code?
begin
puts 'This is Before Exception Arise!'
raise 'Exception Created!'
puts 'After Exception'
end
View Answer
6. Which statement will execute at the end of the code, whether the exception raise or not?
View Answer
7. What will be output for the following code?
begin
raise 'Exception Created!'
puts 'After Exception'
rescue
puts 'Finally Saved!'
ensure
puts 'ensure block execute'
end
View Answer
8. Which block only executes when no exception is raised?
View Answer
9. What will be output for the following code?
begin
puts 'no Exception raise'
rescue
puts 'Finally Saved!'
else
puts 'Else block execute because of no exception raise'
ensure
puts 'ensure block execute'
end
View Answer
10. What will be output for the following code When input number is ""!""?
def catch_and_throw(value)
puts value
a = readline.chomp
throw :value_e if a == ""!""
return a
end
catch :value_e do
number = catch_and_throw(""Enter Number: "")
end
View Answer
Discussion