Module: Dry::Monads::Try::Mixin::Constructors

Included in:
Dry::Monads, Dry::Monads::Try::Mixin
Defined in:
lib/dry/monads/try.rb

Instance Method Summary collapse

Instance Method Details

#Try(*exceptions, &f) ⇒ Try

A convenience wrapper for Dry::Monads::Try.run. If no exceptions are provided it falls back to StandardError. In general, relying on this behaviour is not recommended as it can lead to unnoticed bugs and it is always better to explicitly specify a list of exceptions if possible.

Parameters:

  • exceptions (Array<Exception>)

Returns:



234
235
236
237
# File 'lib/dry/monads/try.rb', line 234

def Try(*exceptions, &f)
  catchable = exceptions.empty? ? Try::DEFAULT_EXCEPTIONS : exceptions.flatten
  Try.run(catchable, f)
end