Skip to main content

Avoid throw in catch block

Rule id

avoid-throw-in-catch-block

Severity

Warning

Description

Call throw in a catch block loses the original stack trace and the original exception.

Since 2.16 version you can use Error.throwWithStackTrace.

Example

void repository() {
try {
networkDataProvider();
} on Object {
throw RepositoryException(); // LINT
}
}