You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When an error is being thrown from a do - catch, the type of the error being thrown is unknown. We might would like to handle some specific types of errors in a specific way, but most of the times the error is being logged to the console or reported to some third party error tracking system. In order to do that, we do not need to unwrap the error without the type itself, it is available for us in the catch statement.
The official Apple documentation on error handling is without a single example of unwrapping an error without specifying the type.
enumError:Swift.Error{case invalidOperation
case failedOperation
}func foo()throws{throwError.invalidOperation
}
Example 1:
do{tryfoo()}catchError.invalidOperation {print("Action failed with invalid operation")}catchError.failedOperation {print("Action failed with failed operation")}catch{print("Action failed for unkown reason. Error: \(error.localizedDescription)")}
Example 2:
do{tryfoo()}catchlet error as Error{print("Action failed with invalid operation")}catch{print("Action failed for unknown reason. Error: \(error.localizedDescription)")}
Example 3:
do{tryfoo()}catchError.invalidOperation {print("Action failed with invalid operation")}catchlet error as Error{print("Action failed with custom error")}catch{print("Action failed for unknown reason. Error: \(error.localizedDescription)")}
Configurable?
The rule should not be configurable.
Opt-in or enabled?
This rule could be a personal preference or coding style from various individuals, so it could be kept as opt-in.
The text was updated successfully, but these errors were encountered:
New Issue Checklist
Rule Request
Description
When an
error
is being thrown from ado - catch
, the type of the error being thrown is unknown. We might would like to handle some specific types of errors in a specific way, but most of the times theerror
is being logged to the console or reported to some third party error tracking system. In order to do that, we do not need to unwrap theerror
without the type itself, it is available for us in thecatch
statement.The official Apple documentation on error handling is without a single example of unwrapping an error without specifying the type.
What would trigger?
What would not trigger?
Example 1:
Example 2:
Example 3:
Configurable?
The rule should not be configurable.
Opt-in or enabled?
This rule could be a personal preference or coding style from various individuals, so it could be kept as opt-in.
The text was updated successfully, but these errors were encountered: