When a Python segment USES
try... except... After
, I don’t know how to locate the detailed program crush
. These two days, the program needs to use this aspect, so I looked it up.
You need to use the Traceback package
import traceback
try:
#Dividing by zero errors is an example
3/0
except Exception, e:
#This is the output for the error category, which is not really visible if the catch is a generic error
print 'str(Exception):\t', str(Exception) #Output str(Exception): <type 'exceptions.Exception'>
#This is the specific reason for the output error.
print 'str(e):\t\t', str(e) #output str(e): integer division or modulo by zero
print 'repr(e):\t', repr(e) # Output repr(e): ZeroDivisionError('integer division or modulo by zero',)
print 'traceback.print_exc():';
#Both of the following steps output the exact location of the error
traceback.print_exc()
print 'traceback.format_exc():\n%s' % traceback.format_exc()
In addition, Python 2.6 except
after the sentence can be replaced with except Exception as e
Read More:
- Python: How to Use try exception to Display Abnormal Error Information
- How does Python output colored fonts in the CMD command line window
- python: File Processing and Input and Output
- How to Fix Errors encountered in executing Python scripts with command line parameters
- [Solved] Python Requests Error: simplejson.errors.JSONDecodeError: Expecting value
- [Solved] Python Error: tensorflow.python.framework.errors_impl.UnknownError: 2 root error(s) found.
- Python errors: valueerror: if using all scalar values, you must pass an index (four solutions)
- How to Solve Python WARNING: Ignoring invalid distribution -ip (e:\python\python_dowmload\lib\site-packages)
- Invalid python sd, Fatal Python error: init_fs_encoding: failed to get the Python cod [How to Solve]
- [Solved] PyCharm pytest-html Install Error: Try to run this command from the system terminal. Make sure that you use
- Detailed explanation of OpenCV approxpolydp() function
- Python opens the table and appears pandas.errors.ParserError: Error tokenizing data. C error:
- Opencv Python realizes the paint filling function in PS, one click filling color and the possible reasons for opencv’s frequent errors
- [Solved] NPM install Error: check python checking for Python executable python2 in the PATH
- [Solved] Mindspot error: Error: runtimeerror:_kernel.cc:88 CheckParam] AddN output shape must be equal to input…
- Python: ___ () vs ___ str__()
- Httprunner output assure Report
- [Solved] opencv-python: recipe for target ‘modules/python3/CMakeFiles/opencv_python3.dir/all‘ failed
- Error:output with shape [1, 224, 224] doesn‘t match the broadcast shape [3, 224, 224]
- Pychar can’t connect to Python console, but it can run. Py file, and Anaconda’s command line can run Python command