missing_exception_value
The method {0} must have an exceptional return value (the second argument) when the return type of the function is neither 'void', 'Handle', nor 'Pointer'.
Description
#The analyzer produces this diagnostic when an invocation of the method
Pointer.fromFunction
or NativeCallable.isolateLocal
doesn't have a second argument (the exceptional
return value) when the type to be returned from the invocation is neither
void
, Handle
, nor Pointer
.
For more information about FFI, see C interop using dart:ffi.
Example
#The following code produces this diagnostic because the type returned by
f
is expected to be an 8-bit integer but the call to fromFunction
doesn't include an exceptional return argument:
import 'dart:ffi';
int f(int i) => i * 2;
void g() {
Pointer.fromFunction<Int8 Function(Int8)>(f);
}
Common fixes
#Add an exceptional return type:
import 'dart:ffi';
int f(int i) => i * 2;
void g() {
Pointer.fromFunction<Int8 Function(Int8)>(f, 0);
}
除非另有说明,文档之所提及适用于 Dart 3.7.3 版本,本页面最后更新时间: 2025-05-08。 查看文档源码 或者 报告页面问题。