summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorLevi Bostian <levi.bostian@gmail.com>2014-11-10 19:45:17 -0600
committerLevi Bostian <levi.bostian@gmail.com>2014-11-10 19:45:17 -0600
commit9ddc2d0a5b92974ac1614024b4586354a395482e (patch)
treee000862eabe61e6df3e8e462b6ec45fd07a6f915
parentfc5eb4af1bcd6d564d7d5b2bd883d7d3342c6547 (diff)
Add Ruby exceptions.
-rw-r--r--ruby.html.markdown14
1 files changed, 14 insertions, 0 deletions
diff --git a/ruby.html.markdown b/ruby.html.markdown
index 3c67de2e..a1a2c77b 100644
--- a/ruby.html.markdown
+++ b/ruby.html.markdown
@@ -10,6 +10,7 @@ contributors:
- ["Marcos Brizeno", "http://www.about.me/marcosbrizeno"]
- ["Ariel Krakowski", "http://www.learneroo.com"]
- ["Dzianis Dashkevich", "https://github.com/dskecse"]
+ - ["Levi Bostian", "https://github.com/levibostian"]
---
@@ -271,6 +272,19 @@ else
end
#=> "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