Skip to content

Commit baa48b7

Browse files
authored
Verbose showerror for SingularException (#1204)
Currently, ```julia julia> A = diagm(0 => [1.0, 0.0]) 2×2 Matrix{Float64}: 1.0 0.0 0.0 0.0 julia> inv(A) ERROR: SingularException(2) [...] ``` After this, ```julia julia> inv(A) ERROR: SingularException: matrix is singular; factorization failed. Zero eigenvalue found at index 2 [...] ```
2 parents e0b59a7 + c550974 commit baa48b7

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

src/exceptions.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ struct SingularException <: Exception
2828
info::BlasInt
2929
end
3030

31+
function Base.showerror(io::IO, ex::SingularException)
32+
print(io, "SingularException: matrix is singular; factorization failed. Zero pivot found at index ", ex.info)
33+
end
34+
3135
"""
3236
PosDefException
3337

test/dense.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1366,4 +1366,9 @@ end
13661366
@test !any(LinearAlgebra.getstructure(A))
13671367
end
13681368

1369+
@testset "SingularException show" begin
1370+
A = diagm(0=> [1, 0])
1371+
@test_throws "matrix is singular; factorization failed" inv(A)
1372+
end
1373+
13691374
end # module TestDense

0 commit comments

Comments
 (0)