Exception: Ashby::Error

Inherits:
StandardError
  • Object
show all
Defined in:
lib/ashby/error.rb,
lib/ashby.rb

Overview

Custom error class for the Ashby module that extends StandardError with optional error code support.

This class provides a standardized way to handle errors within the Ashby module by allowing both error messages and optional error codes to be associated with exceptions.

Examples:

Basic usage with message only

raise Ashby::Error.new("Something went wrong")

Usage with message and error code

raise Ashby::Error.new("API request failed", 500)

Accessing the error code

begin
  raise Ashby::Error.new("Not found", 404)
rescue Ashby::Error => e
  puts e.message  # => "Not found"
  puts e.code     # => 404
end

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message, code = nil) ⇒ Error

Initialize a new Ashby::Error instance

Parameters:

  • message (String)

    The error message

  • code (Object, nil) (defaults to: nil)

    Optional error code (typically an integer, but can be any object)



33
34
35
36
# File 'lib/ashby/error.rb', line 33

def initialize(message, code = nil)
  super(message)
  @code = code
end

Instance Attribute Details

#codeObject? (readonly)

The optional error code associated with this error

Returns:

  • (Object, nil)

    the current value of code



26
27
28
# File 'lib/ashby/error.rb', line 26

def code
  @code
end