import sys try: raise ValueError('this is a exp') except Exception as ex: ex_type, ex_val, ex_stack = sys.exc_info() print(ex_type) print(ex_val)