zoukankan      html  css  js  c++  java
  • 异常处理

    异常

      Error  语法错误  比较明显的错误  在编译代码阶段就能检测出来

      Iteration 异常  在执行代码的过程中引发的异常

    最简单的异常处理

      try:

        pass

      except  IndexError:

        pass

      

      

    多分支异常处理

      try:

        pass

      except ValueError:

        pass

      except IndexError:

        pass

      

      

      

    万能异常   不管什么错都不会报错    万能异常要放在所有except的最后

      try:

        pass

      except Exception as 变量名:

        pass

      

      

      

      

    异常处理的其他机制

      try:

        pass

      except NameError:

        pass

      except Exception:

        pass

      else:  # try中的代码正常执行  没有异常的时候会执行else中的代码

        pass

      finally:  # 无论如何都会执行  操作系统资源归还的工作

        pass

      

      try:

        pass

      finally:

        pass

        

     主动抛异常

      try:

        pass  

      except Exception:

        raise  # 原封不动的抛出try语句中出现的异常

    断言   assert   raise  主动抛异常    布尔值

      assert  True

      if False:

        print(”123“)

      else:

        raise AssertionError

      

      

     

  • 相关阅读:
    基于摸板匹配的目標跟蹤算法
    spoj 2713 Can you answer these queries IV
    zoj 3633 Alice's present
    hdu 3642 Get The Treasury
    poj 1195 Mobile phones
    poj 2760 End of Windless Days
    zoj 3540 Adding New Machine
    spoj 1716 Can you answer these queries III
    spoj 1043 Can you answer these queries I
    spoj 2916 Can you answer these queries V
  • 原文地址:https://www.cnblogs.com/wjs521/p/9456330.html
Copyright © 2011-2022 走看看