The Artima Developer Community
Sponsored Link

Ruby Buzz Forum
Sharing Ruby and Python Exceptions

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Red Handed

Posts: 1158
Nickname: redhanded
Registered: Dec, 2004

Red Handed is a Ruby-focused group blog.
Sharing Ruby and Python Exceptions Posted: Oct 25, 2005 10:26 PM
Reply to this message Reply

This post originated from an RSS feed registered with Ruby Buzz by Red Handed.
Original Post: Sharing Ruby and Python Exceptions
Feed Title: RedHanded
Feed URL: http://redhanded.hobix.com/index.xml
Feed Description: sneaking Ruby through the system
Latest Ruby Buzz Posts
Latest Ruby Buzz Posts by Red Handed
Latest Posts From RedHanded

Advertisement

If you’re coming from Python and using Ruby now (or straddling the both,) you might relate to Jonas Galvez, who prefers the Liberal Feed Parser when parsing RSS and is calling it from Ruby. The sly part is that he’s passing back exceptions to Ruby in YAML. He’s just got a file that defines error codes and his classes are trained to turn those codes into exceptions.

 ERROR_CODES = YAML::load open("config/errorcodes.yml").read

 module MyExceptions
   class MyException < StandardError
   end
   CODES = []
   for k, v in ERROR_CODES
     CODES[v['code']] = const_set(k, Class.new(MyException) {
       define_method :to_s do
         "{code: #{v['code']}, message: #{v['message']}}" 
       end
     })
   end
 end

Not bad at all. I’ll bet you guys will put arms on this thing. A bit more than to_s needs to be defined, I guess. Anyway, touch it, it’s real.

Read: Sharing Ruby and Python Exceptions

Topic: Boardgames meet Programming Previous Topic   Next Topic Topic: RubyConf 2005, the wrap-up

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use