SHARE
TWEET

Untitled

a guest Jun 24th, 2019 59 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # File: exception-13.rb
  2. #
  3. def foo1(a)
  4.   foo2(a)
  5. end
  6.  
  7. def foo2(a)
  8.   foo3(a)
  9. rescue RuntimeError => ex
  10.   puts "An RuntimeError has been encountered. The error message is: #{ex.message}"
  11. rescue RangeError => ex
  12.   puts "A RangeError has been encountered. The error message is: #{ex.message}"
  13. end
  14.  
  15. def foo3(a)
  16.   foo4(a)
  17. end
  18.  
  19. def foo4(a)
  20.   if a >= 10
  21.     raise 'foo4 raised an error because argument given is greater than 10'
  22.   else
  23.     raise RangeError, 'foo4 raised an error because argument given is less than 10'
  24.   end
  25. end
  26.  
  27. print 'Give an integer number: '
  28. a = gets.to_i
  29.  
  30. foo1 a
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top