Skip to content

Commit b8ca548

Browse files
author
Will Kimmerer
committed
Exceptions instead of errors
1 parent 9808484 commit b8ca548

File tree

3 files changed

+39
-8
lines changed

3 files changed

+39
-8
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "SuiteSparseGraphBLAS"
22
uuid = "c2e53296-7b14-11e9-1210-bddfa8111e1d"
33
authors = ["Will Kimmerer <[email protected]", "Abhinav Mehndiratta <[email protected]>"]
4-
version = "0.4.0"
4+
version = "0.4.1"
55

66
[deps]
77
CEnum = "fa961155-64e5-5f13-b03f-caf6b980ea82"

src/lib/LibGraphBLAS.jl

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,15 @@ const GxB_FC64_t = ComplexF32
1010

1111
const GrB_Index = UInt64
1212

13+
struct UninitializedObjectError <: Exception end
14+
struct InvalidObjectError <: Exception end
15+
struct NullPointerError <: Exception end
16+
struct InvalidValueError <: Exception end
17+
struct InvalidIndexError <: Exception end
18+
struct OutputNotEmptyError <: Exception end
19+
struct InsufficientSpaceError <: Exception end
20+
struct PANIC <: Exception end
21+
1322
macro wraperror(code)
1423
MacroTools.@q begin
1524
info = $(esc(code))
@@ -18,7 +27,33 @@ macro wraperror(code)
1827
elseif info == GrB_NO_VALUE
1928
return nothing
2029
else
21-
error(string(info))
30+
if info == GrB_UNINITIALIZED_OBJECT
31+
throw(UninitializedObjectError)
32+
elseif info == GrB_INVALID_OBJECT
33+
throw(InvalidObjectError)
34+
elseif info == GrB_NULL_POINTER
35+
throw(NullPointerError)
36+
elseif info == GrB_INVALID_VALUE
37+
throw(InvalidValueError)
38+
elseif info == GrB_INVALID_INDEX
39+
throw(InvalidIndexError)
40+
elseif info == GrB_DOMAIN_MISMATCH
41+
throw(DomainError(nothing, "GraphBLAS Domain Mismatch"))
42+
elseif info == GrB_DIMENSION_MISMATCH
43+
throw(DimensionMismatch())
44+
elseif info == GrB_OUTPUT_NOT_EMPTY
45+
throw(OutputNotEmptyError)
46+
elseif info == GrB_OUT_OF_MEMORY
47+
throw(OutOfMemoryError())
48+
elseif info == GrB_INSUFFICIENT_SPACE
49+
throw(InsufficientSpaceError)
50+
elseif info == GrB_INDEX_OUT_OF_BOUNDS
51+
throw(BoundsError())
52+
elseif info == GrB_PANIC
53+
throw(PANIC)
54+
else
55+
throw(ErrorException("I don't know how I got here."))
56+
end
2257
end
2358
end
2459
end
@@ -810,7 +845,7 @@ for T ∈ valid_vec
810845
X = Vector{$type}(undef, nvals)
811846
nvals = Ref{GrB_Index}()
812847
$func(I, X, nvals, v)
813-
nvals[] == length(I) == length(X) || error("Mismatched Lengths")
848+
nvals[] == length(I) == length(X) || throw(DimensionMismatch())
814849
return I .+ 1, X
815850
end
816851
end
@@ -962,7 +997,7 @@ for T ∈ valid_vec
962997
X = Vector{$type}(undef, nvals)
963998
nvals = Ref{GrB_Index}(nvals)
964999
$func(I, J, X, nvals, A)
965-
nvals[] == length(I) == length(X) == length(J) || error("Mismatched Lengths")
1000+
nvals[] == length(I) == length(X) == length(J) || throw(DimensionMismatch())
9661001
return I .+ 1, J .+ 1, X
9671002
end
9681003
end

src/operations/ewise.jl

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -316,10 +316,6 @@ function Base.broadcasted(::typeof(-), A::GBArray, B::GBArray)
316316
eadd(A, B, BinaryOps.MINUS)
317317
end
318318

319-
function Base.broadcasted(::typeof(/), A::GBArray, B::GBArray)
320-
emul(A, B, BinaryOps.DIV)
321-
end
322-
323319
#TODO: fix tricky gotchas, this will do type-specific (ie sometimes integer) division.
324320
function Base.broadcasted(::typeof(/), A::GBArray, B::GBArray)
325321
emul(A, B, BinaryOps.DIV)

0 commit comments

Comments
 (0)