python 抛出捕获异常

res_json={
"id": 123456,
"ip": "1.2.3.4"
}

res_str="vpc out limited"
def return_val():
    return res_str

def create_vm():
    try:
        response = return_val()
        return response['id'] #如果response是str 会报:TypeError: string indices must be integers, not str
    except TypeError as e:
        raise Exception(response)
    
#CASE
try:
    id=create_vm()
    print id
except Exception as e:
    print "errinfo %s" %(e)

 

posted on 2020-05-27 22:20  思此狂  阅读(480)  评论(0)    收藏  举报

导航