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 ...@@ -34,12 +34,17 @@ export evaluate_return_code, CaosDBException
using CaosDB 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 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 values of the calls to libccaosdb. May carry a message string and a
code. code.
""" """
struct CaosDBException <: Exception struct GenericCaosDBException <: CaosDBException
msg::String msg::String
code::Cint code::Cint
end end
...@@ -50,7 +55,7 @@ Base.showerror(io::IO, e::CaosDBException) = print(io, "CaosDBException: ", e.ms ...@@ -50,7 +55,7 @@ Base.showerror(io::IO, e::CaosDBException) = print(io, "CaosDBException: ", e.ms
function evaluate_return_code(code::Cint) function evaluate_return_code(code::Cint)
Evaluate the return code of a libccaosdb ccall and raise a 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) function evaluate_return_code(code::Cint)
if code != 0 if code != 0
...@@ -60,7 +65,7 @@ function evaluate_return_code(code::Cint) ...@@ -60,7 +65,7 @@ function evaluate_return_code(code::Cint)
(Cint,), (Cint,),
code code
) )
throw(CaosDBException(unsafe_string(msg), code)) throw(GenericCaosDBException(unsafe_string(msg), code))
end end
end end
......
...@@ -36,5 +36,6 @@ using CaosDB ...@@ -36,5 +36,6 @@ using CaosDB
@testset "TestExceptions" begin @testset "TestExceptions" begin
@test CaosDB.Exceptions.evaluate_return_code(Cint(0)) == nothing @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.CaosDBException CaosDB.Exceptions.evaluate_return_code(Cint(14))
@test_throws CaosDB.Exceptions.GenericCaosDBException CaosDB.Exceptions.evaluate_return_code(Cint(14))
end end
end end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment