Exception Processing 'try' - 'except' method

Once the program error has occurred, and stopped from the wrong position, and not continue behind the content 
using the try and except exception handling can
try is the code that we need to address
the back except with a type of error when an error occurs and the error code is in line with the type of when the code is executed except in
except to support multi-branch
there that can handle all types of errors: Exception
has universal processing mechanisms still need to be able to predict problems alone deal with
all the content should be handled separately written in the universal abnormal before
else: no abnormal when executed else the code
finally: whether the code is abnormal, will be executed
finally meet and return when the execution will still
function with exception handling in doing, whether or not abnormal to do some finishing touches on
the except exception error AS
Print ( 'you're wrong, old iron', error)
  error: here are variables, is being given specific reasons Tip


the try:
name
2 + '. 3'
[] [. 3]
{} [ 'K']
RET = int (INPUT ( '>>> Number'))
Print (RET * '*')
the except a ValueError:
Print ( 'input data is incorrect ')
the except Exception:
Print (' you're wrong, old iron ')
else:
Print (' no exceptions when executing code else in ')
DEF FUNC ():
the try:
f = Open (' File ', 'W')
'' '' ''
return True
the except:
return False
finally:
Print ( 'the finally a')
f.close ()

Print (FUNC ())


try:
main()
except Exception:
pass

the try:
Print ( '1111')
# 1/0
Print ( '2222')
# name
# + 2 '. 3'
# [] [. 3]
# {} [ 'K']
RET = int (INPUT ( 'Number >> > '))
Print (RET *' * ')
the except Exception error AS:
Print (' you're wrong, old iron ', error)

Guess you like

Origin www.cnblogs.com/jmc218/p/11706302.html