The Artima Developer Community
Sponsored Link

Ruby Buzz Forum
Message-oriented (duck-typed) 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
Eigen Class

Posts: 358
Nickname: eigenclass
Registered: Oct, 2005

Eigenclass is a hardcore Ruby blog.
Message-oriented (duck-typed) exceptions Posted: Mar 23, 2007 5:38 AM
Reply to this message Reply

This post originated from an RSS feed registered with Ruby Buzz by Eigen Class.
Original Post: Message-oriented (duck-typed) exceptions
Feed Title: Eigenclass
Feed URL: http://feeds.feedburner.com/eigenclass
Feed Description: Ruby stuff --- trying to stay away from triviality.
Latest Ruby Buzz Posts
Latest Ruby Buzz Posts by Eigen Class
Latest Posts From Eigenclass

Advertisement

I thought somebody would implement the message-oriented exception mechanism I hinted at, but nobody did so here's the obvious implementation (4 minutes wall clock time):

Usage

def foo
  #...
  raise EX[:critical, :alert_user] # if ...
  # ...
end

def bar
  begin
    foo
  rescue EX[:critical]
    puts "Releasing resources"
    raise
  end
end

begin
  bar
rescue EX[:alert_user] => e
  puts "=" * 80
  puts "Bad news:"
  puts e.backtrace
  puts "=" * 80
end
# >> Releasing resources
# >> ================================================================================
# >> Bad news:
# >> -:30:in `foo'
# >> -:36:in `bar'
# >> -:44
# >> ================================================================================

Implementation

Using respond_to? to remain close to the message-oriented nature of huh everything else:


Read more...

Read: Message-oriented (duck-typed) exceptions

Topic: Responses to Matthew Huntbach���s Take on Ruby Previous Topic   Next Topic Topic: First Agile RTP meeting tonight

Sponsored Links



Google
  Web Artima.com   

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