• +91 9723535972
  • info@interviewmaterial.com

Ruby Interview Questions and Answers

Question - Explain the use of ensure statement in Ruby?

Answer -

There is an ensure clause which guarantees some processing at the end of code. The ensure block always run whether an exception is raised or not. It is placed after last rescue clause and will always executed as the block terminates.

The ensure block will run at any case whether an exception arises, exception is rescued or code is terminated by uncaught exception.

Syntax:

begin  
code..  
#..raise exception  
rescue  
#.. exception is rescued  
ensure  
#.. This code will always execute.  
end  

Comment(S)

Show all Coment

Leave a Comment




NCERT Solutions

 

Share your email for latest updates

Name:
Email:

Our partners