class Dry::Monads::Try::Error

Represents a result of a failed execution.

@api public

Public Class Methods

new(exception) click to toggle source

@param exception [Exception]

Calls superclass method
# File lib/dry/monads/try.rb, line 186
def initialize(exception)
  super()

  @exception = exception
end

Public Instance Methods

===(other) click to toggle source

@param other [Try] @return [Boolean]

# File lib/dry/monads/try.rb, line 218
def ===(other)
  Error === other && exception === other.exception
end
inspect()
Alias for: to_s
or(*args) { |exception, *args| ... } click to toggle source

If a block is given passes internal value to it and returns the result, otherwise simply returns the first argument.

@example

Try(ZeroDivisionError) { 1 / 0 }.or { "zero!" } # => "zero!"

@param args [Array<Object>] arguments that will be passed to a block

if one was given, otherwise the first
value will be returned

@return [Object]

# File lib/dry/monads/try.rb, line 208
def or(*args)
  if block_given?
    yield(exception, *args)
  else
    args[0]
  end
end
recover(*errors) { |exception| ... } click to toggle source

Acts in a similar way to ‘rescue`. It checks if {exception} is one of {errors} and yields the block if so.

@param errors [Class] List of Exception subclasses

@return [Try::Value]

# File lib/dry/monads/try.rb, line 228
def recover(*errors)
  if errors.empty?
    classes = DEFAULT_EXCEPTIONS
  else
    classes = errors
  end

  if classes.any? { _1 === exception }
    Value.new([exception.class], yield(exception))
  else
    self
  end
end
to_maybe() click to toggle source

@return [Maybe::None]

# File lib/dry/monads/maybe.rb, line 425
def to_maybe
  Maybe::None.new(RightBiased::Left.trace_caller)
end
to_result() click to toggle source

@return [Result::Failure]

# File lib/dry/monads/result.rb, line 452
def to_result
  Result::Failure.new(exception, RightBiased::Left.trace_caller)
end
to_s() click to toggle source

@return [String]

# File lib/dry/monads/try.rb, line 193
def to_s
  "Try::Error(#{exception.class}: #{exception.message})"
end
Also aliased as: inspect