Apuntes_Python/02_conceptos/10_logging/d_captura_stack_traces.py

29 lines
491 B
Python
Raw Normal View History

2022-12-24 22:41:20 -03:00
"""
Captura de stack traces
"""
import logging
print('Captura de error:\n')
try:
a = [1,2,3]
val = a[4]
except IndexError as e:
logging.error(e)
print('\n\nCaptura de error mas seguimiento:\n')
try:
a = [1,2,3]
val = a[4]
except IndexError as e:
logging.error(e, exc_info=True)
print('\n\nCaptura de error desconocido y seguimiento:\n')
import traceback
try:
a = [1,2,3]
val = a[4]
except:
logging.error('El error es %s', traceback.format_exc())