njh / ruby-mqtt

Pure Ruby gem that implements the MQTT protocol, a lightweight protocol for publish/subscribe messaging.
http://www.rubydoc.info/gems/mqtt
MIT License
541 stars 135 forks source link

Derive Exceptions from StandardError #112

Open ahanak opened 6 years ago

ahanak commented 6 years ago

Thanks for the nice library.

I think that exceptions should be derived from the ruby StandardError. This makes it possible to rescue them in a general rescue block.

It will result in the following code to work as expected:

require 'mqtt'
begin
  MQTT::Client.connect('test.mosquitto.org') do |c|
    c.get('test') do |topic,message|
      puts "#{topic}: #{message}"
    end
  end
rescue
  puts "Something went wrong."
end
njh commented 6 years ago

I think this is very likely to be a good idea.

However I suspect it may have to be a 'major' version release / API breaking change - some people might be depending on it not being a StandardError in their code.

ahanak commented 6 years ago

You're right here. There won't be an effect for most cases, but I'ts an API change.

SixiS commented 6 years ago

+1

lostapathy commented 5 years ago

+1, this is a change worth making.

bkbyler commented 1 year ago

:+1: This change would have saved me hours (days?) of debugging.