DatingBot icon indicating copy to clipboard operation
DatingBot copied to clipboard

Refactor code to handle errors more precisely

Open DavidRomanovizc opened this issue 1 year ago • 0 comments

Example code with try-except block covering the entire code block:

How not to do it

try:
    # some code here
except:
    print("Error occurred")

Example code with more accurate error handling:

How to do it right

# some code here
try:
    result = some_function() # function that we expect might raise an exception
except SomeSpecificError as e:
    # handle specific error
    logging.error(f"Error occurred: {e}")
except Exception as e:
    # handle any other unexpected errors
    logging.error(f"Unexpected error occurred: {e}")

It is necessary to check the entire code and correct where this occurs.

  • [ ] Handlers

  • https://github.com/DavidRomanovizc/DatingBot/blob/decf861ee7b33b6142ffa2c40debf2a77dd14531/handlers/users/view_event_handler.py#L17

  • https://github.com/DavidRomanovizc/DatingBot/blob/decf861ee7b33b6142ffa2c40debf2a77dd14531/handlers/users/start_handler.py#L23

  • https://github.com/DavidRomanovizc/DatingBot/blob/decf861ee7b33b6142ffa2c40debf2a77dd14531/handlers/users/start_handler.py#L46

  • https://github.com/DavidRomanovizc/DatingBot/blob/decf861ee7b33b6142ffa2c40debf2a77dd14531/handlers/users/start_handler.py#L105

  • https://github.com/DavidRomanovizc/DatingBot/blob/decf861ee7b33b6142ffa2c40debf2a77dd14531/handlers/users/registration_handler.py#L77

  • https://github.com/DavidRomanovizc/DatingBot/blob/decf861ee7b33b6142ffa2c40debf2a77dd14531/handlers/users/registration_handler.py#L98

  • https://github.com/DavidRomanovizc/DatingBot/blob/decf861ee7b33b6142ffa2c40debf2a77dd14531/handlers/users/registration_handler.py#L135

  • https://github.com/DavidRomanovizc/DatingBot/blob/decf861ee7b33b6142ffa2c40debf2a77dd14531/handlers/users/registration_handler.py#L153

  • https://github.com/DavidRomanovizc/DatingBot/blob/decf861ee7b33b6142ffa2c40debf2a77dd14531/handlers/users/registration_handler.py#L172

  • https://github.com/DavidRomanovizc/DatingBot/blob/decf861ee7b33b6142ffa2c40debf2a77dd14531/handlers/users/filters_handler.py#L35

  • https://github.com/DavidRomanovizc/DatingBot/blob/decf861ee7b33b6142ffa2c40debf2a77dd14531/handlers/users/filters_handler.py#L52

  • https://github.com/DavidRomanovizc/DatingBot/blob/decf861ee7b33b6142ffa2c40debf2a77dd14531/handlers/users/filters_handler.py#L88

  • https://github.com/DavidRomanovizc/DatingBot/blob/decf861ee7b33b6142ffa2c40debf2a77dd14531/handlers/users/filters_handler.py#L126

  • https://github.com/DavidRomanovizc/DatingBot/blob/decf861ee7b33b6142ffa2c40debf2a77dd14531/handlers/users/event_list_handler.py#L13

DavidRomanovizc avatar May 02 '23 19:05 DavidRomanovizc