forked from zhanghe06/python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_except.py
More file actions
51 lines (37 loc) · 921 Bytes
/
test_except.py
File metadata and controls
51 lines (37 loc) · 921 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/env python
# encoding: utf-8
"""
@author: zhanghe
@software: PyCharm
@file: test_except.py
@time: 16-4-13 下午6:38
"""
import time
import traceback
def test_01():
try:
# raise Exception('error_message')
raise Exception('error_message', 'error_code')
except Exception as e:
# 打印异常
print type(e), e
time.sleep(0.1)
# 打印异常消息
print type(e.message), e.message
time.sleep(0.1)
# 打印异常参数
print e.args, type(e.args[0]), e.args[0]
time.sleep(0.1)
# 打印异常堆栈跟踪信息 stack traceback
traceback.print_exc()
def test_02():
try:
print u'try'
raise Exception(u'try')
except Exception as e:
print u'except'
raise Exception(u'except')
finally:
print u'finally'
if __name__ == '__main__':
test_02()