Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Derive Exceptions from StandardError #112

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Conversation

ahanak
Copy link

@ahanak ahanak commented Apr 19, 2018

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
Copy link
Owner

njh commented Apr 19, 2018

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
Copy link
Author

ahanak commented Apr 19, 2018

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

@SixiS
Copy link

SixiS commented Aug 22, 2018

+1

@lostapathy
Copy link

+1, this is a change worth making.

@bkbyler
Copy link

bkbyler commented May 25, 2023

👍 This change would have saved me hours (days?) of debugging.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants