Exception trap
try: execpt Exception as e: print(str(e))
Print exception information the way
1 str (e)
Returns a string type, given only abnormality information , abnormality information does not include the type of abnormality information such as 1/0
'integer division or modulo by zero'
2、e.message
The information obtained with the str (e)
3, repr (s)
Given wide than the abnormality information , including the type of the abnormality information, abnormality information such as 1/0
"ZeroDivisionError('integer division or modulo by zero',)"
4, using the traceback module
Need to import traceback module, the most complete information acquired at this time, appear to python command line to run the same program error messages.
traceback.print_exc (): print exception information to standard error, as there is no get, like,
traceback.format_exc (): Get the same output as a string. You can pass a variety of parameters to these functions to limit the output
Reproduced in: https: //www.cnblogs.com/faithfu/p/10937496.html