rbs icon indicating copy to clipboard operation
rbs copied to clipboard

How to declare that an exception is thrown

Open HoneyryderChuck opened this issue 5 years ago • 16 comments

I didn't find in the documentation how to declare if an exception can be thrown. Is this something that will be supported?

HoneyryderChuck avatar Oct 16 '20 16:10 HoneyryderChuck

We don't have a plan to support it for now. (Future version may have it, but not in Ruby 3.0.)

soutaro avatar Oct 17 '20 07:10 soutaro

What should be the type of a return value of a method that can raise an exception?

For example:

def do_stuff
  raise unless all_ok?

  42
end

Option 1:

def do_stuff: -> Integer

Every time a value is returned it's actually an Integer but this seem to not account for times when the method doesn't return a value but raises an exception instead.

Option 2:

def do_stuff: -> Integer | nil

This seem incorrect because nil is never actually returned from the method.

Option 3:

def do_stuff: -> Integer | void

This seem a little closer to reality but I'm uncertain. void signals "no useful value" returned but an exception is not exactly a return value.

pointlessone avatar Jan 12 '24 09:01 pointlessone