diff --git a/NEWS.md b/NEWS.md index 936ecd94..9a2128a5 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,6 +1,7 @@ - v0.1.5 - Patch for Julia PR [#20889](https://github.com/JuliaLang/julia/pull/20889), which changes how lowering is done for exponentiation of integer literals. - Bug fix to enable registering Main as a module for `u_str` (fixes [#61](https://github.com/ajkeller34/Unitful.jl/issues/61)). + - Implement readable message for `DimensionError` [#62](https://github.com/ajkeller34/Unitful.jl/pull/62). - v0.1.4 - Critical bug fix owing to `mod_fast` changes. - v0.1.3 diff --git a/src/Conversion.jl b/src/Conversion.jl index a3c72b7b..92ab25be 100644 --- a/src/Conversion.jl +++ b/src/Conversion.jl @@ -47,7 +47,7 @@ Find the conversion factor from unit `t` to unit `s`, e.g. `convfact(m,cm) = 0.0 # Check if conversion is possible in principle sdim = dimension(s()) tdim = dimension(t()) - sdim != tdim && throw(DimensionError(s,t)) + sdim != tdim && throw(DimensionError(s(),t())) # first convert to base SI units. # fact1 is what would need to be multiplied to get to base SI units diff --git a/src/Unitful.jl b/src/Unitful.jl index 3418bdf6..b4b1a1c4 100644 --- a/src/Unitful.jl +++ b/src/Unitful.jl @@ -54,13 +54,16 @@ type DimensionError{T,S} <: Exception y::S end ``` -Thrown when dimensions don't match in an operation that demands they do. Display `x` and `y` in error message. + +Thrown when dimensions don't match in an operation that demands they do. +Display `x` and `y` in error message. """ type DimensionError{T,S} <: Exception - x::T - y::S + x::T + y::S end -Base.showerror(io::IO, e::DimensionError) = print(io,"DimensionError: $(e.x) and $(e.y) are not dimensionally compatible."); +Base.showerror(io::IO, e::DimensionError) = + print(io,"DimensionError: $(e.x) and $(e.y) are not dimensionally compatible."); """ ``` diff --git a/src/range.jl b/src/range.jl index d94cb8ff..1fb3c6a0 100644 --- a/src/range.jl +++ b/src/range.jl @@ -10,18 +10,18 @@ linspace(Float64, ustrip(start), ustrip(stop), len, 1)*unit(T) function _linspace{T}(start::Quantity{T}, stop::Quantity{T}, len::Integer) - dimension(start) != dimension(stop) && throw(DimensionError()) + dimension(start) != dimension(stop) && throw(DimensionError(start, stop)) linspace(start, stop, len) end @compat function colon(start::Quantity{<:Real}, step, stop::Quantity{<:Real}) - dimension(start) != dimension(stop) && throw(DimensionError()) + dimension(start) != dimension(stop) && throw(DimensionError(start, stop)) T = promote_type(typeof(start),typeof(stop)) return colon(convert(T,start), step, convert(T,stop)) end function colon(start::A, step::B, stop::A) where A<:Quantity{<:Real} where B<:Quantity{<:Real} - dimension(start) != dimension(step) && throw(DimensionError()) + dimension(start) != dimension(step) && throw(DimensionError(start, step)) colon(promote(start, step, stop)...) end