ruby-mqtt icon indicating copy to clipboard operation
ruby-mqtt copied to clipboard

Derive Exceptions from StandardError

Open ahanak opened this issue 6 years ago • 5 comments

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

ahanak avatar Apr 19 '18 07:04 ahanak

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.

njh avatar Apr 19 '18 09:04 njh

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

ahanak avatar Apr 19 '18 15:04 ahanak

+1

SixiS avatar Aug 22 '18 12:08 SixiS

+1, this is a change worth making.

lostapathy avatar Nov 16 '18 16:11 lostapathy

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

bkbyler avatar May 25 '23 23:05 bkbyler