Complete the code to define a custom exception class named MyError.
class MyError < [1] end
Custom exceptions in Ruby usually inherit from StandardError to behave like typical errors.
Complete the code to raise the custom exception MyError with a message.
raise [1], "Something went wrong"
To raise a custom exception with a message, use raise MyError, "message".
Fix the error in the code to rescue the custom exception MyError.
begin # some code rescue [1] => e puts e.message end
To catch a custom exception, rescue it by its class name MyError.
Fill both blanks to define a custom exception with a message method.
class MyError < [1] def [2] "Custom error occurred" end end
initialize instead of message changes how the error is created.The custom exception inherits from StandardError and defines a message method to return the error message.
Fill all three blanks to raise and rescue a custom exception with a message.
begin raise [1], "Oops!" rescue [2] => e puts e.[3] end
e.to_s instead of e.message changes output format.This code raises MyError with a message, rescues it, and prints the message using e.message.