Catching Errors

The following example illustrates how to catch TileDB errors.

// Create TileDB context
tiledb_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 occurred
  tiledb_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 error
  tiledb_error_free(&err);
}

// Clean up
tiledb_ctx_free(&ctx);

Last updated