[ linter ] Add diagnostic docs for avoid_catches_without_on_clauses

Closes https://github.com/dart-lang/sdk/pull/63091

GitOrigin-RevId: dc7973d9519ee66691bc0ea1667d8f6382bf6584
Change-Id: If2dab19ebdd9592f032c47cd3f17622fd4f35686
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/492282
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Connie Ooi <connieooi@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
This commit is contained in:
Ildeberto Vasconcelos
2026-04-29 15:56:04 -07:00
committed by dart-scoped@luci-project-accounts.iam.gserviceaccount.com
parent 55f91b69a5
commit 334c96a4b1
+35
View File
@@ -989,6 +989,41 @@ LinterLintCode:
stable: "2.0"
categories: [effectiveDart, style]
hasPublishedDocs: false
documentation: |-
#### Description
The analyzer produces this diagnostic when a `catch` clause lacks an
`on` clause to specify the exception type. Catching all exceptions
can mask unexpected errors and make debugging more difficult.
#### Example
The following code produces this diagnostic because the `catch` clause
has no `on` clause to specify the exception type:
```dart
void f() {
try {
int.parse('?');
} [!catch!] (e) {
print(e);
}
}
```
#### Common fixes
Add an `on` clause to specify the type of exception to catch:
```dart
void f() {
try {
int.parse('?');
} on FormatException catch (e) {
print(e);
}
}
```
deprecatedDetails: |-
From [Effective Dart](https://dart.dev/effective-dart/usage#avoid-catches-without-on-clauses):