nullable_ type_ in_ catch_ clause
Details about the 'nullable_type_in_catch_clause' diagnostic produced by the Dart analyzer.
A potentially nullable type can't be used in an 'on' clause because it isn't valid to throw a nullable expression.
Description
#
The analyzer produces this diagnostic when the type following
on in a catch clause is a nullable
type. It isn't valid to specify a nullable type because it
isn't possible to catch null (because it's a
runtime error to throw null).
Example
#
The following code produces this diagnostic because the
exception type is specified to allow null when
null can't be thrown:
void f() {
try {
// ...
} on FormatException? {
// ...
}
}
Common fixes
#Remove the question mark from the type:
void f() {
try {
// ...
} on FormatException {
// ...
}
}
除非另有说明,文档之所提及适用于 Dart 3.12.2 版本报告页面问题.