From: Joel VanderWerf Date: 2005-09-16T01:31:37+09:00 Subject: Re: classifying exceptions nobuyoshi nakada wrote: > Hi, > > At Thu, 15 Sep 2005 14:57:22 +0900, > Joel VanderWerf wrote in [ruby-talk:156196]: > >>Now, here's another option, but is there anything wrong with it? >> >>module NetworkRaisable; end >>class Errno::EPROTO; include NetworkRaisable; end >>class Errno::ECONNREFUSED; include NetworkRaisable; end >># and so on >> >>begin >> raise Errno::ECONNREFUSED >>rescue NetworkRaisable >> puts "OK!" >>end > > > Actually, an exception, to be caught, doesn't have to be > including target module always. > > module NetworkRaisable > def self.===(ex) > case ex > when Errno::EPROTO, Errno::ECONNREFUSED: true > end > end > end > Thanks, that's better. I forgot rescue uses case-matching. And it avoids modifying ruby built-in classes. (And NetworkRaisable doesn't even have to be a module.) -- vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407