Python raise Exception assert traceback.format_exc

1.Python 抛出异常

 

def test(symbol):
    if symbol == 1:
        raise Exception('can not be 1')

try:
    test(1)
except Exception as err:
    print(str(err))

 

2.Python Assert

testP = 3
assert testP >= 4, 'testP must >= 4'

 

3.可以用traceback.format_exc() 打印出具体的异常信息

import traceback
print(traceback.format_exc())

http://www.waitingfy.com/archives/1838

1838

Leave a Reply

Name and Email Address are required fields.
Your email will not be published or shared with third parties.