我正在制作一个自定义插件来查询数据库中的用户信息以帮助客户支持。我的后端是松弛的。
每次我启动 bot 命令时,我都会收到:
Computer says nooo. See logs for details:
catching classes that do not inherit from BaseException is not allowed
Run Code Online (Sandbox Code Playgroud)
我不确定这是否警告我我正在尝试捕获不是我的代码中 BaseClass 的异常,或者是否在我的插件之外的其他地方引发并捕获了未知异常。
为了调试我试过:
try:
do_the_thing()
except (TypeError, ValueError) as e:
return('Something went wrong.')
Run Code Online (Sandbox Code Playgroud)
我也试过:
try:
do_the_thing()
except Exception as e:
return('Something went wrong.')
Run Code Online (Sandbox Code Playgroud)
我仍然收到 errbot 的警告。请注意,在 do_the_thing() 没有引发异常的情况下,该命令仍会运行并执行正确的操作。