How to declare that an exception is thrown
I didn't find in the documentation how to declare if an exception can be thrown. Is this something that will be supported?
We don't have a plan to support it for now. (Future version may have it, but not in Ruby 3.0.)
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.