throwIfError method

void throwIfError(
  1. int result,
  2. Pointer<ExternError> err,
  3. String label
)

Throws an exception if a BBS+ library operation results in an error.

This utility function is used to check the result of FFI calls to the BBS+ library. If the operation fails (i.e., result is non-zero), the function reads the error message from the provided ExternError pointer and throws an Exception with the appropriate error description.

Implementation

void throwIfError(int result, Pointer<ExternError> err, String label) {
  if (result != 0) {
    final msg = err.ref.message == nullptr
        ? 'Unknown error'
        : err.ref.message.toDartString();
    calloc.free(err);
    throw Exception('$label: $msg');
  }
}