OLD | NEW |
---|---|
1 # Copyright 2017 The Chromium Authors. All rights reserved. | 1 # Copyright 2017 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 import functools | 5 import functools |
6 import logging | 6 import logging |
7 | 7 |
8 | 8 |
9 def Memoize(f): | 9 def Memoize(f): |
10 """Decorator to cache return values of function.""" | 10 """Decorator to cache return values of function.""" |
(...skipping 13 matching lines...) Expand all Loading... | |
24 Args: | 24 Args: |
25 default_return_value: Value to return in the case of uncaught Exception. | 25 default_return_value: Value to return in the case of uncaught Exception. |
26 exception_message: Message for uncaught exceptions. | 26 exception_message: Message for uncaught exceptions. |
27 """ | 27 """ |
28 def decorator(f): | 28 def decorator(f): |
29 @functools.wraps(f) | 29 @functools.wraps(f) |
30 def wrapper(*args, **kwargs): | 30 def wrapper(*args, **kwargs): |
31 try: | 31 try: |
32 return f(*args, **kwargs) | 32 return f(*args, **kwargs) |
33 except Exception: # pylint: disable=broad-except | 33 except Exception: # pylint: disable=broad-except |
34 logging.exception('Ignore the following exception.') | |
jbudorick
2017/04/25 18:14:48
This will log the exception twice, which we defini
BigBossZhiling
2017/04/26 20:55:47
Done.
| |
34 logging.exception(exception_message) | 35 logging.exception(exception_message) |
35 return default_return_value | 36 return default_return_value |
36 return wrapper | 37 return wrapper |
37 return decorator | 38 return decorator |
OLD | NEW |