53 await self.load_extension("cogs." + a[:-3])
54 print(f"Loading {a[:-3]}.py")
55
56 except Exception as e:57 print(f"Unable to load {a}\n{e}")
58 print(traceback.format_exc())
59
55 try:
56 with redirect_stdout(stdout):
57 ret = await func()
58 except Exception as e:59 value = stdout.getvalue()
60 await ctx.send(f"```py\n{value}{traceback.format_exc()}\n```")
61 else:
48
49 try:
50 exec(to_compile, env)
51 except Exception as e:52 return await ctx.send(f"```py\n{e.__class__.__name__}: {e}\n```")
53
54 func = env["func"]
121 if font == "default"
122 else pyfiglet.figlet_format(text, font=font)
123 )
124 except Exception as e:125 if isinstance(e, pyfiglet.FontNotFound):
126 return await ctx.send("Font not found! Insert another one.")
127
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')