exemple décorateur suppression exception
This commit is contained in:
parent
ee356a248e
commit
fe29c16feb
|
@ -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))
|
||||
|
Loading…
Reference in New Issue