Complete the code to raise a RuntimeError with a message.
raise [1], "Something went wrong!"
throw or catch instead of an error class.raise.The raise keyword is used to throw an exception. RuntimeError is a common error type to raise with a message.
Complete the code to raise a custom error with a message.
class MyError < StandardError; end raise [1], "Custom error occurred"
Exception or Error instead of the custom class.To raise a custom error, use the custom class name after raise. Here, MyError is the custom error class.
Fix the error in the code to correctly raise an ArgumentError with a message.
raise ArgumentError [1] "Invalid argument!"
When raising an error with a message, separate the error class and message with a comma.
Complete the code to raise a ZeroDivisionError with a custom message.
raise [1] , "Cannot divide by zero!"
ArgumentError.The error class ZeroDivisionError is raised with a message separated by a comma.
Fill all three blanks to raise a custom error with a message and rescue it.
class [1] < StandardError; end begin raise [2], "Oops!" rescue [3] => e puts e.message end
Define a custom error class CustomError, raise it, and rescue it by the same class to handle the error.