htg-public/python3/wrap_exception.py

22 lines
342 B
Python

#!/usr/bin/env python3
#-*- coding: utf-8 -*-
def _no_index_error(func):
"""
"""
def wrapper(*args, **kwargs):
try:
return func(*args, **kwargs)
except IndexError:
return
return wrapper
a = [1]
@_no_index_error
def get_5_element(liste):
return liste[4]
print(get_5_element(a))