Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace except Exceptions with proper error handling #1508

Open
yoonthegoon opened this issue Aug 4, 2023 · 2 comments
Open

Replace except Exceptions with proper error handling #1508

yoonthegoon opened this issue Aug 4, 2023 · 2 comments

Comments

@yoonthegoon
Copy link
Contributor

image

Catching all errors with Exception is enticing, but has several issues.
Properly catching the errors you expect to get:

  1. improves readability and maintainability
  2. improves error diagnostics
  3. avoids unexpected behavior

There are cases where you may be passing one argument to a function that requires two, like filter that will go unnoticed while running or testing, as the error it raises just gets caught by a bare Exception.
I want to avoid situations like this; exceptions should catch only expected behavior.

@leebaird
Copy link
Collaborator

leebaird commented Aug 5, 2023

Love this idea.

@sbajary
Copy link
Contributor

sbajary commented May 30, 2024

First, There Another approach to solve this with the general exception, using the following code:
print(f'An exception has occurred: {e.__class__.__name__} : {url}')
will show us the exception type without specifying custom solution for every type

Second, The annoying thing about this, is there are many messages printed after exceptions caught.
see the following as sample:

An exception has occurred: ContentTypeError : https://sonar.omnisint.io/all/www.edge-security.com?page=640
An exception has occurred: ContentTypeError : https://sonar.omnisint.io/all/www.edge-security.com?page=870
An exception has occurred: ContentTypeError : https://sonar.omnisint.io/all/www.edge-security.com?page=180
An exception has occurred: ContentTypeError : https://sonar.omnisint.io/all/www.edge-security.com?page=90
An exception has occurred: ContentTypeError : https://sonar.omnisint.io/all/www.edge-security.com?page=610
An exception has occurred: ContentTypeError : https://sonar.omnisint.io/all/www.edge-security.com?page=110
An exception has occurred: ContentTypeError : https://sonar.omnisint.io/all/www.edge-security.com?page=710
An exception has occurred: ContentTypeError : https://sonar.omnisint.io/all/www.edge-security.com?page=440
An exception has occurred: ContentTypeError : https://sonar.omnisint.io/all/www.edge-security.com?page=420
An exception has occurred: ContentTypeError : https://sonar.omnisint.io/all/www.edge-security.com?page=140
An exception has occurred: ContentTypeError : https://sonar.omnisint.io/all/www.edge-security.com?page=950
An exception has occurred: ContentTypeError : https://sonar.omnisint.io/all/www.edge-security.com?page=350
An exception has occurred: ContentTypeError : https://sonar.omnisint.io/all/www.edge-security.com?page=750
An exception has occurred: ContentTypeError : https://sonar.omnisint.io/all/www.edge-security.com?page=450
An exception has occurred: ContentTypeError : https://sonar.omnisint.io/all/www.edge-security.com?page=120
An exception has occurred: ContentTypeError : https://sonar.omnisint.io/all/www.edge-security.com?page=930
An exception has occurred: ContentTypeError : https://sonar.omnisint.io/all/www.edge-security.com?page=700
An exception has occurred: ContentTypeError : https://sonar.omnisint.io/all/www.edge-security.com?page=510
An exception has occurred: ContentTypeError : https://sonar.omnisint.io/all/www.edge-security.com?page=720
An exception has occurred: ContentTypeError : https://sonar.omnisint.io/all/www.edge-security.com?page=340
An exception has occurred: ContentTypeError : https://sonar.omnisint.io/all/www.edge-security.com?page=980
An exception has occurred: ContentTypeError : https://sonar.omnisint.io/all/www.edge-security.com?page=370
An exception has occurred: ContentTypeError : https://sonar.omnisint.io/all/www.edge-security.com?page=480
An exception has occurred: ContentTypeError : https://sonar.omnisint.io/all/www.edge-security.com?page=130
An exception has occurred: ContentTypeError : https://sonar.omnisint.io/all/www.edge-security.com?page=530
An exception has occurred: ContentTypeError : https://sonar.omnisint.io/all/www.edge-security.com?page=270
An exception has occurred: ContentTypeError : https://sonar.omnisint.io/all/www.edge-security.com?page=310
An exception has occurred: ContentTypeError : https://sonar.omnisint.io/all/www.edge-security.com?page=240
An exception has occurred: ContentTypeError : https://sonar.omnisint.io/all/www.edge-security.com?page=320

it's the same exception caught but from different threads. it's so annoying.

Third, There are errors that do not require continuing to work such as ServerDisconnectedError or the availability internet connection. All it requires is to show the error and stop the rest of the work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants