Ruby Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesRuby Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old January 23rd, 2012, 10:21 PM
haosmark haosmark is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2012
Posts: 2 haosmark User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 26 m 22 sec
Reputation Power: 0
Exceptions

I'm building an error handler by a book and I think it's not working as it should. According to the book, the code should output only 2 lines (wording is a bit different, I know):
Quote:
You gave me some bad input: Who knows?
! GenderError ("Invalid input!")


but I get only the first line, followed by, I guess actual errors in my error handler. Here's the console text:
Quote:
incorrect input value: fuzzy
C:/Users/PC/Documents/Eclipse/test_project/custom exceptions.rb:14:in `define_gender': What's this? Invalid input? (GenderError)
from C:/Users/PC/Documents/Eclipse/test_project/custom exceptions.rb:19:in `initialize'
from C:/Users/PC/Documents/Eclipse/test_project/custom exceptions.rb:26:in `new'
from C:/Users/PC/Documents/Eclipse/test_project/custom exceptions.rb:26:in `<main>'


Here's the code itself:
Code:
class GenderError < RuntimeError
  attr :what_they_put
  
  def initialize(their_input)
    @what_they_put = their_input
  end
end



class Person
  def define_gender(gender)
    if (gender.upcase != 'FEMALE') && (gender.upcase != 'MALE')
      raise GenderError.new(gender), "What's this? Invalid input?"
    end
  end
  
  def initialize(gender)
    self.define_gender(gender)
  rescue GenderError => e
    puts "incorrect input value: " + e.what_they_put
    raise
  end
end

dude = Person.new("fuzzy")


I spent an hour now looking at this code, trying to figure out the error with no results... Can anyone help?

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesRuby Programming > Exceptions

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap