Home / Programming Questions / Ruby MCQs / Page 16

Ruby MCQs with answers Page - 16

Dear candidates you will find MCQ questions of Ruby here. Learn these questions and prepare yourself for coming examinations and interviews. You can check the right answer of any question by clicking on any option or by clicking view answer button.
Share your questions by clicking Add Question

Code:
begin
         
    puts 'This is Before Exception Arise!'
         
       raise 'Exception Created!'
   
    puts 'After Exception' 
end
(A) This is Before Exception Arise! After Exception!
(B) Exception Created! After Exception!
(C) This is Before Exception Arise! Exception Created!
(D) This is Before Exception Arise! Exception Created! After exception

(A) retry
(B) raise
(C) ensure
(D) else

Code:
begin
         
    raise 'Exception Created!'
   
    puts 'After Exception' 
   
  rescue    
    puts 'Finally Saved!'
    
ensure
   puts 'ensure block execute'
end
(A) ensure block execute
(B) After exception! Finally Saved! ensure block execute
(C) Ecxception Created! Finally Saved! ensure block execute
(D) Finally Saved! ensure block execute

(A) retry
(B) raise
(C) ensure
(D) else

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
(A) no Exception raise Else block execute because of no exception raise ensure block execute
(B) no Exception raise Else block execute because of no exception raise
(C) Finally Saved! Else block execute because of no exception raise ensure block execute
(D) None of the above

Code:
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
(A) Error
(B) 0
(C) Nil
(D) Infinite Loop

Login

Forgot username? click here

Forgot password? Click here

Don't have account? Register here.