Ruby 3 · Errors and files
Raise a custom error
Subclass StandardError for your own exceptions, then raise and rescue it.
class ValidationError < StandardError; end
begin
raise ValidationError, "name is required"
rescue ValidationError => e
puts e.message
end