unused_catch_clause 진단

unused_catch_clause 진단

unused_catch_clause는 catch 절에서 예외 매개변수와 선택적인 스택 트레이스 매개변수를 catch 블록 안에서 전혀 사용하지 않을 때 Dart 분석기가 알려주는 진단이에요.

출처: unused_catch_clause

본문

분석기는 catch 절을 발견했는데, 그 catch 블록 안에서 예외 매개변수도 선택적 스택 트레이스 매개변수도 사용되지 않을 때 이 진단을 만들어요.

예시

다음 코드는 e가 참조되지 않기 때문에 이 진단이 발생해요.

void f() {
  try {
    int.parse(';');
  } on FormatException catch (e) {
    // ignored
  }
}

해결 방법

사용하지 않는 catch 절을 제거해주세요.

void f() {
  try {
    int.parse(';');
  } on FormatException {
    // ignored
  }
}

더 알아보기