File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ #!/usr/bin/python
2+ # Filename: try_except.py
3+
4+ import sys
5+
6+ try :
7+ s = raw_input ('Enter something --> ' )
8+ except EOFError :
9+ print '\n Why did you do an EOF on me?'
10+ sys .exit () # exit the program
11+ except :
12+ print '\n Some error/exception occurred.'
13+ # here, we are not exiting the program
14+
15+ print 'Done'
Original file line number Diff line number Diff line change 1+ #!/usr/bin/env python
2+
3+ '''
4+ try:
5+ Normal execution block
6+ except A:
7+ Exception A handle
8+ except B:
9+ Exception B handle
10+ except:
11+ Other exception handle
12+ else:
13+ if no exception,get here
14+ finally:
15+ print("finally")
16+ '''
17+
18+
19+ class AError (Exception ):
20+ """AError---exception"""
21+ print ('AError' )
22+
23+
24+ try :
25+ # raise AError
26+ asdas ('123' )
27+ except AError :
28+ print ("Get AError" )
29+ except :
30+ print ("exception" )
31+ else :
32+ print ("else" )
33+ finally :
34+ print ("finally" )
35+ print ("hello wolrd" )
You can’t perform that action at this time.
0 commit comments