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
Exceptions should be reserved for truly exceptional cases. There are many occurrences of exception abuse, overusing try-blocks, and excepting Exception when a function throws a specific exception.
Non-compliant
def_unfollow_company(self) ->None:
try:
logger.debug("Unfollowing company")
follow_checkbox=self.driver.find_element(
By.XPATH, "//label[contains(.,'to stay up to date with their page.')]")
follow_checkbox.click()
exceptExceptionase:
logger.debug(f"Failed to unfollow company: {e}")
Compliant
# compliantdef_unfollow_company(self) ->None:
logger.debug("Unfollowing company") # Does not throw exception - has no reason to be in the try-block# Handle one function that throws an error at a timetry:
# find_element() only throws a NoSuchElementException - there's no reason to catch a general exceptionfollow_checkbox=self.driver.find_element(By.XPATH, "//label[contains(.,'to stay up to date with their page.')]")
exceptNoSuchElementExceptionase:
logger.debug(f"Failed to unfollow company: {e}")
# Does not throw exception - has no reason to be in the try-blockfollow_checkbox.click()
Motivation
It significantly improves maintainability and readability
Alternatives considered
No, the current approach to error handling and exception abuse as flow control is unacceptable.
Additional context
No response
The text was updated successfully, but these errors were encountered:
Feature summary
Exceptions are not meant for flow control
Feature description
Exceptions should be reserved for truly exceptional cases. There are many occurrences of exception abuse, overusing try-blocks, and excepting Exception when a function throws a specific exception.
Non-compliant
Compliant
Motivation
It significantly improves maintainability and readability
Alternatives considered
No, the current approach to error handling and exception abuse as flow control is unacceptable.
Additional context
No response
The text was updated successfully, but these errors were encountered: