From: "Iñaki Baz Castillo" Date: 2011-04-23T03:15:25+09:00 Subject: Is it usual/valid to extend custom classes under Errno module? Hi, I've coded a DNS library. When a DNS query fails my library doesn't raise an exception (as it's expensive) but instead returns a Symbol (more efficient): - :dns_error_nxdomain - The domain name does not exist. - :dns_error_nodata - There is no data of requested type found. - :dns_error_tempfail - Temporary error, the resolver nameserver was not able to process our query or timed out. - :dns_error_protocol - Protocol error, a nameserver returned malformed reply. An example usage: ----------------------------------------------------------- resolver = EM::Udns::Resolver.new EM::Udns.run resolver query = resolver.submit_A "google.com" query.callback do |result| puts "result => #{result.inspect}" end query.errback do |error| case error when :dns_error_nxdomain # do something when :dns_error_nodata # do something when :dns_error_tempfail # do something end end -------------------------------------------------------------- So returning a Symbol (in case of failure) is good as I can use it within a case/when statement. Another possibility would be returning an instance of a class, something like: class EM::Udns::ErrorNoDomain < EM::Udns::Error ; end class EM::Udns::ErrorNoData < EM::Udns::Error ; end class EM::Udns::ErrorTempFail < EM::Udns::Error ; end or I could extend Errno module: class Errno::DnsNoDomain ; end class Errno::DnsNoData ; end class Errno::DnsTempail ; end In your opinnion, which is the most elegant way? any other suggestion? Thanks a lot. -- Iñaki Baz Castillo