class

Unit::ConversionError

Inherits Unit::UnitError < Exception < Reference < Object

Exception raised when a conversion between units fails. This typically happens when attempting to convert between incompatible measurement types (e.g., weight to length).

Example:

begin
  weight = Weight.new(10, :kg)
  length = Length.new(5, :m)
  # This would raise ConversionError:
  # weight + length
rescue ex : Unit::ConversionError
  puts ex.message # => "Cannot convert from Weight to Length: Incompatible measurement types"
end

Constructors

new(from_unit : String, to_unit : String, reason : String | Nil = nil)
Source
new(from_unit, to_unit, reason = nil)

Alternative constructor that accepts unit types directly

Source

Class methods

incompatible_types(from_type : T.class, to_type : U.class) forall T, U

Factory method for incompatible type conversions

Source

Instance methods

from_unit
Source
reason
Source
to_unit
Source