开发者

Suppressing traceback (stack trace) for caught exceptions in Python

开发者 https://www.devze.com 2023-04-06 01:57 出处:网络
I have python code that catches an exception: # ... except Exception: # Handle the exception When this code is executed, the traceback (stack trace) is printed to the console. How can I sup开发者_开

I have python code that catches an exception:

# ...
except Exception:
    # Handle the exception

When this code is executed, the traceback (stack trace) is printed to the console. How can I sup开发者_开发百科press it?


Not recommended, but

except Exception:
    pass

Will silently ignore the exception. However, if you don't fix what went wrong, your program may quit anyways because something further down in your code will throw another exception. You should at the least print out a message stating what happened, or debugging your code can be a nightmare.

0

精彩评论

暂无评论...
验证码 换一张
取 消