• Python handling an exception


    #try...except...
    try:
       You do your operations here;
       ......................
    except ExceptionI:
       If there is ExceptionI, then execute this block.
    except ExceptionII:
       If there is ExceptionII, then execute this block.
       ......................
    else:
       If there is no exception then execute this block. 
    
    #The except Clause with No Exceptions
    try:
       You do your operations here;
       ......................
    except:
       If there is any exception, then execute this block.
       ......................
    else:
       If there is no exception then execute this block. 
    
    #The except Clause with Multiple Exceptions
    try:
       You do your operations here;
       ......................
    except(Exception1[, Exception2[,...ExceptionN]]]):
       If there is any exception from the given exception list, 
       then execute this block.
       ......................
    else:
       If there is no exception then execute this block. 
    
    #The try-finally Clause
    try:
       You do your operations here;
       ......................
       Due to any exception, this may be skipped.
    finally:
       This would always be executed.
       ......................
    
    #Argument of an Exception
    try:
       You do your operations here;
       ......................
    except ExceptionType, Argument:
       You can print value of Argument here...
    

      

  • 相关阅读:
    一个省一等奖没文件没证书,只能保存一张图呢
    HTML5的新结构标签
    一个最简单的网页是如何构成的
    数据模型层Model
    空控制器空操作
    TP框架
    thinkphp基础
    静态缓存
    smarty函数
    Smarty的使用
  • 原文地址:https://www.cnblogs.com/KennyRom/p/6294536.html
Copyright © 2020-2023  润新知