在第二个中,您可以访问异常对象的属性:
>>> def catch():... try:... asd()... except Exception as e:... print e.message, e.args... >>> catch()global name 'asd' is not defined ("global name 'asd' is not defined",)
但是它不会捕获
baseException或系统退出异常
SystemExit,
KeyboardInterrupt并且
GeneratorExit:
>>> def catch():... try:... raise baseException()... except Exception as e:... print e.message, e.args... >>> catch()Traceback (most recent call last): File "<stdin>", line 1, in <module> File "<stdin>", line 3, in catchbaseException
除了一个裸露的:
>>> def catch():... try:... raise baseException()... except:... pass... >>> catch()>>>
有关更多信息,请参见文档的“内置异常”部分和本教程的“错误与异常”部分。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)