exemple décorateur suppression exception

This commit is contained in:
motius 2017-04-27 21:09:55 +02:00
parent ee356a248e
commit fe29c16feb
1 changed files with 21 additions and 0 deletions

21
python3/wrap_exception.py Normal file
View File

@ -0,0 +1,21 @@
#!/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))