Mailinglist Archive: opensuse-ruby (23 mails)

< Previous Next >
[opensuse-ruby] Don't confuse raise+rescue with throw+catch.
  • From: Martin Vidner <mvidner@xxxxxxx>
  • Date: Fri, 2 Oct 2009 08:50:45 +0200
  • Message-id: <20091002065045.GA7855@xxxxxxxxxxxxxxxxxx>
First post11!

Just a reminder, I have just fixed a bug:
http://git.opensuse.org/?p=projects/yast/web-client.git;a=commitdiff;h=6412a2edd4215cad514586479695747bf8822573

To illustrate how it bites, the attached program does this
$ ruby snippets/throw-rescue.rb
Doing it right
I have rescued Ouch!
Doing it wrong
I have rescued Exception is not a symbol

--
Martin Vidner, YaST developer
http://en.opensuse.org/User:Mvidner

Kuracke oddeleni v restauraci je jako fekalni oddeleni v bazenu
#!/usr/bin/env ruby

def doit_right
puts "Doing it right"
raise Exception, "Ouch!"
end

def doit_wrong
puts "Doing it wrong"
throw Exception, "Ouch!"
end

begin
doit_right
rescue Exception => e
puts "I have rescued #{e}"
end
begin
doit_wrong
rescue Exception => e
puts "I have rescued #{e}"
end
< Previous Next >
List Navigation
Follow Ups