MyAppError that inherits from StandardError.DatabaseError and NetworkError that inherit from MyAppError.DatabaseError exception.MyAppError and print a message.MyAppError that inherits from StandardError.DatabaseError and NetworkError that inherit from MyAppError.DatabaseError exception.MyAppError and print a message.MyAppError that inherits from StandardError.Use class MyAppError < StandardError to create the base exception class.
DatabaseError and NetworkError that inherit from MyAppError.Define each subclass with class ClassName < MyAppError.
DatabaseError exception with the message "Database connection failed".Use raise DatabaseError, "Database connection failed" to raise the exception.
DatabaseError inside a begin block. Rescue the exception using MyAppError and print "Caught an error: " followed by the exception message.Use begin and rescue MyAppError => e to catch the error and puts to print the message.
Which class is the root of the exception hierarchy in Ruby?
Exception class, which is the root of the hierarchy.StandardError and RuntimeError are subclasses of Exception.Which of the following is the correct way to rescue only StandardError exceptions in Ruby?
begin # some code rescue ??? puts 'Error caught' end
rescue keyword can specify which exception class to catch by naming it after rescue.StandardError exceptions, write rescue StandardError.What will be the output of this Ruby code?
begin raise IOError, 'File error' rescue StandardError => e puts e.class end
IOError with message 'File error'.StandardError and its subclasses. IOError is a subclass of StandardError, so it is caught.e.class, which is IOError.Find the error in this Ruby code snippet:
begin raise 'Oops!' rescue IOError puts 'IO error caught' end
'Oops!' creates a RuntimeError by default.IOError, but the raised error is RuntimeError, so it is not caught.You want to catch all exceptions except system-exiting ones like SystemExit and Interrupt. Which class should you rescue to catch most errors but allow system exits?
SystemExit and Interrupt inherit directly from Exception, not StandardError.StandardError catches most runtime errors but excludes system-exiting exceptions.Exception catches everything including system exits, which is usually not desired.Pass the test and this pattern moves unknown