• <bdo id='csSMh'></bdo><ul id='csSMh'></ul>
  • <tfoot id='csSMh'></tfoot>

    <small id='csSMh'></small><noframes id='csSMh'>

      <legend id='csSMh'><style id='csSMh'><dir id='csSMh'><q id='csSMh'></q></dir></style></legend>
        <i id='csSMh'><tr id='csSMh'><dt id='csSMh'><q id='csSMh'><span id='csSMh'><b id='csSMh'><form id='csSMh'><ins id='csSMh'></ins><ul id='csSMh'></ul><sub id='csSMh'></sub></form><legend id='csSMh'></legend><bdo id='csSMh'><pre id='csSMh'><center id='csSMh'></center></pre></bdo></b><th id='csSMh'></th></span></q></dt></tr></i><div id='csSMh'><tfoot id='csSMh'></tfoot><dl id='csSMh'><fieldset id='csSMh'></fieldset></dl></div>

        except: 和 except Exception as e 之间的区别:

        Difference between except: and except Exception as e:(except: 和 except Exception as e 之间的区别:)
      1. <i id='cup7S'><tr id='cup7S'><dt id='cup7S'><q id='cup7S'><span id='cup7S'><b id='cup7S'><form id='cup7S'><ins id='cup7S'></ins><ul id='cup7S'></ul><sub id='cup7S'></sub></form><legend id='cup7S'></legend><bdo id='cup7S'><pre id='cup7S'><center id='cup7S'></center></pre></bdo></b><th id='cup7S'></th></span></q></dt></tr></i><div id='cup7S'><tfoot id='cup7S'></tfoot><dl id='cup7S'><fieldset id='cup7S'></fieldset></dl></div>

                <bdo id='cup7S'></bdo><ul id='cup7S'></ul>

                  <legend id='cup7S'><style id='cup7S'><dir id='cup7S'><q id='cup7S'></q></dir></style></legend>
                    <tbody id='cup7S'></tbody>

                  <small id='cup7S'></small><noframes id='cup7S'>

                  <tfoot id='cup7S'></tfoot>
                1. 本文介绍了except: 和 except Exception as e 之间的区别:的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  Both the following snippets of code do the same thing. They catch every exception and execute the code in the except: block

                  Snippet 1 -

                  try:
                      #some code that may throw an exception
                  except:
                      #exception handling code
                  

                  Snippet 2 -

                  try:
                      #some code that may throw an exception
                  except Exception as e:
                      #exception handling code
                  

                  What is exactly the difference in both the constructs?

                  解决方案

                  In the second you can access the attributes of the exception object:

                  >>> 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",)
                  

                  But it doesn't catch BaseException or the system-exiting exceptions SystemExit, KeyboardInterrupt and 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 catch
                  BaseException
                  

                  Which a bare except does:

                  >>> def catch():
                  ...     try:
                  ...         raise BaseException()
                  ...     except:
                  ...         pass
                  ... 
                  >>> catch()
                  >>> 
                  

                  See the Built-in Exceptions section of the docs and the Errors and Exceptions section of the tutorial for more info.

                  这篇关于except: 和 except Exception as e 之间的区别:的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Split a Pandas column of lists into multiple columns(将 Pandas 的列表列拆分为多列)
                  How does the @property decorator work in Python?(@property 装饰器在 Python 中是如何工作的?)
                  What is the difference between old style and new style classes in Python?(Python中的旧样式类和新样式类有什么区别?)
                  How to break out of multiple loops?(如何打破多个循环?)
                  How to put the legend out of the plot(如何将传说从情节中剔除)
                  Why is the output of my function printing out quot;Nonequot;?(为什么我的函数输出打印出“无?)

                    <small id='xJ2hZ'></small><noframes id='xJ2hZ'>

                      <tbody id='xJ2hZ'></tbody>
                    <tfoot id='xJ2hZ'></tfoot>

                        • <bdo id='xJ2hZ'></bdo><ul id='xJ2hZ'></ul>
                          <legend id='xJ2hZ'><style id='xJ2hZ'><dir id='xJ2hZ'><q id='xJ2hZ'></q></dir></style></legend>
                        • <i id='xJ2hZ'><tr id='xJ2hZ'><dt id='xJ2hZ'><q id='xJ2hZ'><span id='xJ2hZ'><b id='xJ2hZ'><form id='xJ2hZ'><ins id='xJ2hZ'></ins><ul id='xJ2hZ'></ul><sub id='xJ2hZ'></sub></form><legend id='xJ2hZ'></legend><bdo id='xJ2hZ'><pre id='xJ2hZ'><center id='xJ2hZ'></center></pre></bdo></b><th id='xJ2hZ'></th></span></q></dt></tr></i><div id='xJ2hZ'><tfoot id='xJ2hZ'></tfoot><dl id='xJ2hZ'><fieldset id='xJ2hZ'></fieldset></dl></div>