Ruby menangkap semua pengecualian
begin
raise 'This exception will be rescued!'
rescue StandardError => e
puts "Rescued: #{e.inspect}"
end
Yucky Yak
begin
raise 'This exception will be rescued!'
rescue StandardError => e
puts "Rescued: #{e.inspect}"
end
def read_array()
name_array = Array.new()
print("How many lines are you entering? ")
count = gets.to_i
index = 0
while (index < count)
print("Enter next: ")
name_array << gets.chomp
index += 1
end
index = 0
print("Printing lines:\n")
while (index < count)
puts(index.to_s() + ' ' + name_array[index])
index += 1
end
end
def print_array(a)
index = 0
print("Printing lines:\n")
while (index < count)
puts(index.to_s() + ' ' + name_array[index])
index += 1
end
end
def main()
read_array()
print_array()
end
main