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

ENH: Add basic exception handling

parent 05dda29d
Branches
No related tags found
1 merge request!1DRAFT: ENH: Include libcaosdb and a minimal wrapper
Pipeline #10003 failed
......@@ -20,6 +20,8 @@
* <https://www.gnu.org/licenses/>.
*
*/
#include <string>
#include <jlcxx/jlcxx.hpp>
#include "caosdb/authentication.h"
......@@ -33,4 +35,12 @@ JLCXX_MODULE define_julia_module(jlcxx::Module& mod)
mod.method("get_libcaosdb_version_major", []() {return caosdb::LIBCAOSDB_VERSION_MAJOR;});
mod.method("get_libcaosdb_version_minor", []() {return caosdb::LIBCAOSDB_VERSION_MINOR;});
mod.method("get_libcaosdb_version_patch", []() {return caosdb::LIBCAOSDB_VERSION_PATCH;});
// exceptions inherit from abstract Julia exception types:
mod.add_type<caosdb::exceptions::AuthenticationError>("AuthenticationError", jlcxx::julia_type("AbstractAuthenticationError"))
.constructor<const std::string&>()
.method("what", &caosdb::exceptions::AuthenticationError::what);
mod.add_type<caosdb::exceptions::ConnectionError>("ConnectionError", jlcxx::julia_type("AbstractConnectionError"))
.constructor<const std::string&>()
.method("what", &caosdb::exceptions::ConnectionError::what);
}
......@@ -5,6 +5,15 @@ module CaosDB
using CxxWrap
"Generic super type of CaosDB exceptions"
abstract type AbstractCaosDBException <: Exception end
"An error occurred while trying to authenticate"
abstract type AbstractAuthenticationError <: AbstractCaosDBException end
"Connection couldn't be established"
abstract type AbstractConnectionError <: AbstractCaosDBException end
# Adapt this path if you haven't compiled jlcaosdb to `caosdb-julialib/build`
@wrapmodule(joinpath(@__DIR__, "../jlcaosdb/build/lib/libjlcaosdb"))
......@@ -26,4 +35,8 @@ function get_libcaosdb_version()
return "$major.$minor.$patch"
end
# Override the exception printing
Base.showerror(io::IO, e::AuthenticationError) = print(io, what(e))
Base.showerror(io::IO, e::ConnectionError) = print(io, what(e))
end # module
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment