Exception Handling Flashcards

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

What are the statements we can use with Exception handling in Ruby?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q
Errors are handled by a dedicated class. True or False?
If so mention the class name
A

True. Errors are handled by Exception class.

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

Name some built in sub classes of exception class?

A

The built-in subclasses of Exception are:

NoMemoryError
LoadError
SyntaxError
SecurityError
Interrupt
StandardError
ArgumentError
LocalJumpError
NameError
NoMethodError
RangeError
RuntimeError
SystemCallError
TypeError
ZeroDivisionError
SystemExit
Fatal
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is the use of cause method in Exception?

A

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.

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

What is the use of backtrace method in Exception?

A

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.”

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