From 9ddc2d0a5b92974ac1614024b4586354a395482e Mon Sep 17 00:00:00 2001 From: Levi Bostian Date: Mon, 10 Nov 2014 19:45:17 -0600 Subject: Add Ruby exceptions. --- ruby.html.markdown | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'ruby.html.markdown') 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 -- cgit v1.2.3 From 1c4cbd279e740f4782c62e75d1f4659447dc464a Mon Sep 17 00:00:00 2001 From: Levi Bostian Date: Tue, 11 Nov 2014 13:06:57 -0600 Subject: Add colon to introduce the exception handling section --- ruby.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ruby.html.markdown') diff --git a/ruby.html.markdown b/ruby.html.markdown index a1a2c77b..e58c513d 100644 --- a/ruby.html.markdown +++ b/ruby.html.markdown @@ -272,7 +272,7 @@ else end #=> "OK job" -# exception handling +# exception handling: begin # code here that might raise an exception raise NoMemoryError, 'You ran out of memory.' -- cgit v1.2.3