The following example illustrates how to catch TileDB errors.
// Create TileDB contexttiledb_ctx_t* ctx;tiledb_ctx_alloc(NULL, &ctx);​// Create a group. The code below creates a group `my_group` and prints a// message because (normally) it will succeed.tiledb_group_create(ctx, "my_group");​// Create the same group again. If we attempt to create the same group// `my_group` as shown below, TileDB will return an error.int rc = tiledb_group_create(ctx, "my_group");if (rc == TILEDB_OK) {// Retrieve the last error that occurredtiledb_error_t* err = NULL;tiledb_ctx_get_last_error(ctx, &err);​// Retrieve and print the error message.const char* msg;tiledb_error_message(err, &msg);printf("%s\n", msg);​// Clean up errortiledb_error_free(&err);}​// Clean uptiledb_ctx_free(&ctx);
// Create TileDB contextContext ctx;​// Catch an errortry {// Create a group. The code below creates a group `my_group` and prints a// message because (normally) it will succeed.create_group(ctx, "my_group");// Create the same group again. If we attempt to create the same group// `my_group` as shown below, TileDB will return an error.create_group(ctx, "my_group");} catch (tiledb::TileDBError& e) {std::cout << "TileDB exception:\n" << e.what() << "\n";}​// Set a different error handlerctx.set_error_handler([](std::string msg) {std::cout << "Callback:\n" << msg << "\n";});​// The following will print the error message using the error// handler set abovecreate_group(ctx, "my_group");
# The Python API raises two kinds of errors:# - Python errors, such as ValueError and KeyError# - tiledb.libtiledb.TileDBError from libtiledbimport tiledbfrom tiledb.libtiledb import TileDBError​try:tiledb.group_create("my_group")# Create the same group againtiledb.group_create("my_group")except TileDBError as err:print("TileDB exception: ", err)
# Create TileDB contextctx <- tiledb_ctx()​result = tryCatch({# Create a group. The code below creates a group `my_group` and prints a# message because (normally) it will succeed.tiledb_group_create("my_group", ctx=ctx)# Create the same group again. If we attempt to create the same group# `my_group` as shown below, TileDB will return an error.tiledb_group_create("my_group", ctx=ctx)}, warning = function(w) {cat(w)}, error = function(e) {cat(e)}, finally = {}
try {ctx = new Context();// Create a group. The code below creates a group `my_group` and prints a// message because (normally) it will succeed.Group group1 = new Group(ctx, "my_group");// Create the same group again. If we attempt to create the same group// `my_group` as shown below, TileDB will return an error.Group group2 = new Group(ctx, "my_group");} catch (TileDBError tileDBError) {tileDBError.printStackTrace();}
// Create TileDB contextctx, _ := NewContext(nil)​// Create a group. The code below creates a group `my_group` and prints a// message because (normally) it will succeed.tiledb.GroupCreate(ctx, "my_group");​// Create the same group again. If we attempt to create the same group// `my_group` as shown below, TileDB will return an error.err := tiledb.GroupCreate(ctx, "my_group");if err != nil {// Retrieve the last error that occurred// Clean up errorerr2 = ctx.LastError()​// Retrieve and print the error message.fmt.Println(err2)}​// Clean upctx.Free()
​
​
​