50 try:
51 app.add_handler(handler, group)
52 success_handlers += 1
53 except Exception as e:54 failed_handlers += 1
55 logging.warning(
56 f"Can't add {module_path}.{name}.{handler.__name__}: {e.__class__.__name__}: {e}"
55 logging.warning(
56 f"Can't add {module_path}.{name}.{handler.__name__}: {e.__class__.__name__}: {e}"
57 )
58 except Exception as e:59 logging.warning(
60 f"Can't import module {module_path}: {e.__class__.__name__}: {e}"
61 )
70 await app.send_photo(msg.chat.id, photo=img,
71 reply_to_message_id=rep)
72 # Dumb exception handler :v
73 except Exception as e:74 # print(e)
75 logging.warning(e)
76
If the except block catches a very general exception, it is likely to catch any unrelated errors too. Try to be more explicit about which exception(s) you're trying to catch.
If you need to catch every other exception, then mark it as intentional by
adding a # skipcq
comment.
try:
x = a / b
except Exception:
x = a / (b + 1)
try:
line = input('Enter numbers:')
numbers = [int(i) for i in line.split()]
except BaseException:
print('Only use numbers for the input')
try:
x = a / b
except ZeroDivisionError:
x = a / (b + 1)
try:
event_loop.run()
except Exception as exc: # skipcq: PYL-W0703 - Loop can sometimes crash.
sentry.report(exc)
try:
line = input('Enter numbers:')
numbers = [int(i) for i in line.split()]
except ValueError:
print('Only use numbers for the input')