Exception Handling Flashcards
What are the statements we can use with Exception handling in Ruby?
retry - This statement is used to execute the rescue block again from the beginning after capturing the exception.
ensure - This statement is used to raise an exception.
else - This statement ensures that required instructions will execute at the end of the code
raise - This statement is present in between the rescue block and ensure block. This block only executes when no exception is raised.
Errors are handled by a dedicated class. True or False? If so mention the class name
True. Errors are handled by Exception class.
Name some built in sub classes of exception class?
The built-in subclasses of Exception are:
NoMemoryError LoadError SyntaxError SecurityError Interrupt StandardError ArgumentError LocalJumpError NameError NoMethodError RangeError RuntimeError SystemCallError TypeError ZeroDivisionError SystemExit Fatal
What is the use of cause method in Exception?
This method returns the previous exception ($!) at the time this exception was raised. This is useful for wrapping exceptions and retaining the original exception information.
What is the use of backtrace method in Exception?
This method returns any backtrace associated with the exception. The backtrace is an array of strings, each containing either “filename:lineNo: in `method”‘ or “filename:lineNo.”