From fe29c16feb83f926ef20b5034a5df7beb2ec31ea Mon Sep 17 00:00:00 2001 From: motius Date: Thu, 27 Apr 2017 21:09:55 +0200 Subject: [PATCH] =?UTF-8?q?exemple=20d=C3=A9corateur=20suppression=20excep?= =?UTF-8?q?tion?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- python3/wrap_exception.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 python3/wrap_exception.py 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)) +