diff --git a/python3/wrap_exception.py b/python3/wrap_exception.py new file mode 100644 index 0000000..bbf353f --- /dev/null +++ b/python3/wrap_exception.py @@ -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)) +