From 5caa4facbbc2c337ffa48cb9874d40eca80f49d2 Mon Sep 17 00:00:00 2001 From: Marek Kaluba Date: Sat, 19 Jun 2021 00:48:04 +0200 Subject: [PATCH] add ProductNotDefined error --- src/mstructures.jl | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/mstructures.jl b/src/mstructures.jl index 2d4e13f..e2dd4a1 100644 --- a/src/mstructures.jl +++ b/src/mstructures.jl @@ -13,6 +13,21 @@ _product(::Val{true}, g, h) = star(g) * h # additionally it may implement # * basis(ms) +struct ProductNotDefined <: Exception + i::Any + j::Any + msg::Any +end + +function Base.showerror(io::IO, ex::ProductNotDefined) + print(io, "Product of elements $(ex.i) and $(ex.j) is not defined on the basis") + print(io, " or the multiplicative structure could not be completed") + if isdefined(ex, :msg) + print(io, ": $(ex.msg)") + end + print(io, ".") +end + struct TrivialMStructure{Tw,I,B<:AbstractBasis} <: MultiplicativeStructure{Tw,I} basis::B end @@ -28,5 +43,6 @@ Base.@propagate_inbounds function Base.getindex(mstr::TrivialMStructure, i::Inte b = basis(mstr) g, h = b[i], b[j] gh = _product(mstr, g, h) + gh in b || throw(ProductNotDefined(i, j, "$g ยท $h = $gh")) return b[gh] end