checkPhidgetError function

void checkPhidgetError(
  1. int res,
  2. String operation
)

Implementation

void checkPhidgetError(int res, String operation) {
  if (res != PhidgetErrorCode.EPHIDGET_OK) {
    final errorStrPtr = calloc<Pointer<Utf8>>();
    try {
      phidgetGetErrorDescriptionFunction(res, errorStrPtr);
      final errorMessage = (errorStrPtr.value == nullptr)
          ? "Unknown Phidget Error (could not get description)"
          : errorStrPtr.value.toDartString();
      throw Exception('Phidget Error during $operation: "$errorMessage" (Code: ${PhidgetErrorCode(res).value})');
    } finally {
      calloc.free(errorStrPtr);
    }
  }
}