Untyped Error in Catch

Catch statements should not declare error variables without type casting

  • Identifier: untyped_error_in_catch
  • Enabled by default: No
  • Supports autocorrection: Yes
  • Kind: idiomatic
  • Analyzer rule: No
  • Minimum Swift compiler version: 5.0.0
  • Default configuration:
    KeyValue
    severity warning

Non Triggering Examples

do {
  try foo()
} catch {}
do {
  try foo()
} catch Error.invalidOperation {
} catch {}
do {
  try foo()
} catch let error as MyError {
} catch {}
do {
  try foo()
} catch var error as MyError {
} catch {}
do {
    try something()
} catch let e where e.code == .fileError {
    // can be ignored
} catch {
    print(error)
}

Triggering Examples

do {
  try foo()
} catch var error {}
do {
  try foo()
} catch let error {}
do {
  try foo()
} catch let someError {}
do {
  try foo()
} catch var someError {}
do {
  try foo()
} catch let e {}
do {
  try foo()
} catch(let error) {}
do {
  try foo()
} catch (let error) {}