Skip to content
Snippets Groups Projects
Commit cdb670c0 authored by florian's avatar florian
Browse files

ENH: Introduce abstract CaosDB exception type

parent f4041bad
No related branches found
No related tags found
1 merge request!4ENH: Add minimal functionality
......@@ -34,12 +34,17 @@ export evaluate_return_code, CaosDBException
using CaosDB
"""
The parent type of all CaosDB errors that can also be used for testing.
"""
abstract type CaosDBException <: Exception end
"""
A generic exception that will be raised in case of non-zero return
values of the calls to libccaosdb. May carry a message string and a
code.
"""
struct CaosDBException <: Exception
struct GenericCaosDBException <: CaosDBException
msg::String
code::Cint
end
......@@ -50,7 +55,7 @@ Base.showerror(io::IO, e::CaosDBException) = print(io, "CaosDBException: ", e.ms
function evaluate_return_code(code::Cint)
Evaluate the return code of a libccaosdb ccall and raise a
`CaosDBException` in case of a non-zero return code.
`GenericCaosDBException` in case of a non-zero return code.
"""
function evaluate_return_code(code::Cint)
if code != 0
......@@ -60,7 +65,7 @@ function evaluate_return_code(code::Cint)
(Cint,),
code
)
throw(CaosDBException(unsafe_string(msg), code))
throw(GenericCaosDBException(unsafe_string(msg), code))
end
end
......
......@@ -36,5 +36,6 @@ using CaosDB
@testset "TestExceptions" begin
@test CaosDB.Exceptions.evaluate_return_code(Cint(0)) == nothing
@test_throws CaosDB.Exceptions.CaosDBException CaosDB.Exceptions.evaluate_return_code(Cint(14))
@test_throws CaosDB.Exceptions.GenericCaosDBException CaosDB.Exceptions.evaluate_return_code(Cint(14))
end
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment