Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

try except to specific line

try:
    func1()
except Exception as ex:
    trace = []
    tb = ex.__traceback__
    while tb is not None:
        trace.append({
            "filename": tb.tb_frame.f_code.co_filename,
            "name": tb.tb_frame.f_code.co_name,
            "lineno": tb.tb_lineno
        })
        tb = tb.tb_next
    print(str({
        'type': type(ex).__name__,
        'message': str(ex),
        'trace': trace
    }))
Comment

PREVIOUS NEXT
Code Example
Python :: swapping 
Python :: all combinations 
Python :: python matplotlib pyplot set axis equals 
Python :: music distorted on discord 
Python :: how to average only positive number in array numpy 
Python :: geopandas read postgis SQL 
Python :: python print 2d array as table 
Python :: how to check if text is lower in python 
Python :: python add hyphen to string 
Python :: python np.sum 
Python :: joblib example 
Python :: star program in python using for loop 
Python :: python standard normal cumulative distribution 
Python :: django run manage.py from python 
Python :: python cursor placement 
Python :: pandas mean of n columns 
Python :: how to append a tuple to a list 
Python :: django not migrating 
Python :: python tkinter treeview column width auto 
Python :: find item in list 
Python :: best way to access nested key in python 
Python :: image data generator keras with tf.data.Data.from_generator 
Python :: print string python 
Python :: allow x_frame_options django 
Python :: python for in range 
Python :: drf serializer 
Python :: recursion python examples 
Python :: phython to c converter 
Python :: remove all consecutive duplicates from the string 
Python :: pandas order dataframe by column of other dataframe 
ADD CONTENT
Topic
Content
Source link
Name
2+7 =