ruby-mqtt
ruby-mqtt copied to clipboard
Derive Exceptions from StandardError
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
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.
You're right here. There won't be an effect for most cases, but I'ts an API change.
+1
+1, this is a change worth making.
:+1: This change would have saved me hours (days?) of debugging.