We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 22ba9ff commit d0cad42Copy full SHA for d0cad42
Trading/utils/chain_exceptions.py
@@ -0,0 +1,19 @@
1
+from typing import Callable, Any, List
2
+
3
4
+def chain_exceptions(
5
+ function_to_apply: Callable[..., Any],
6
+ exceptions: List[Exception],
7
+ default_return=None,
8
+ *args,
9
+ **kwargs
10
+) -> Any:
11
+ '''
12
+ Chain exceptions in a way that the function_to_apply is executed and if it raises an exception,
13
+ the exception is appended to the exceptions list and the default_return is returned.
14
15
+ try:
16
+ return function_to_apply(*args, **kwargs)
17
+ except Exception as e:
18
+ exceptions.append(e)
19
+ return default_return
0 commit comments