mirror of
https://github.com/adambard/learnxinyminutes-docs.git
synced 2024-12-23 17:41:41 +00:00
Merge pull request #853 from levibostian/ruby-exception
Add Ruby exceptions.
This commit is contained in:
commit
ad951f2615
@ -10,6 +10,7 @@ contributors:
|
|||||||
- ["Marcos Brizeno", "http://www.about.me/marcosbrizeno"]
|
- ["Marcos Brizeno", "http://www.about.me/marcosbrizeno"]
|
||||||
- ["Ariel Krakowski", "http://www.learneroo.com"]
|
- ["Ariel Krakowski", "http://www.learneroo.com"]
|
||||||
- ["Dzianis Dashkevich", "https://github.com/dskecse"]
|
- ["Dzianis Dashkevich", "https://github.com/dskecse"]
|
||||||
|
- ["Levi Bostian", "https://github.com/levibostian"]
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@ -271,6 +272,19 @@ else
|
|||||||
end
|
end
|
||||||
#=> "OK job"
|
#=> "OK job"
|
||||||
|
|
||||||
|
# exception handling:
|
||||||
|
begin
|
||||||
|
# code here that might raise an exception
|
||||||
|
raise NoMemoryError, 'You ran out of memory.'
|
||||||
|
rescue NoMemoryError => exception_variable
|
||||||
|
puts 'NoMemoryError was raised', exception_variable
|
||||||
|
rescue RuntimeError => other_exception_variable
|
||||||
|
puts 'RuntimeError was raised now'
|
||||||
|
else
|
||||||
|
puts 'This runs if no exceptions were thrown at all'
|
||||||
|
ensure
|
||||||
|
puts 'This code always runs no matter what'
|
||||||
|
end
|
||||||
|
|
||||||
# Functions
|
# Functions
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user