Обработка исключений

class IsNilException < StandardError
end

class IsEmptyException < StandardError
end

def throw_when_null_or_empty(data)   
    raise IsNilException if data == nil

    raise IsEmptyException if data.size == 0
end

begin
    throw_when_null_or_empty(nil)
rescue Exception => e
    puts "Error: #{e}"
end