Iacutone.rb

coding and things

Exceptions in Ruby

| Comments

I inherited some interesting code last week. A user has the ability to sign into the website with omniauth.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
def num
  puts "Enter a number"
  num = gets.chomp.to_i

  if num == 3
      puts "It's a 3!"
      else
          raise "Wrong number, you entered a #{num}"
  end
end

def num2
  num
end

begin
  num2
rescue Exception => ex
  puts ex
end

Reference

Ruby Exception Class

Comments