try_else_none#
- ivy.try_else_none(fn, *args, **kwargs)[source]#
Try and return the function, otherwise return None if an exception was raised during function execution.
- Parameters:
fn (
Callable
) – Function to try and call and return.args (
Any
) – list of arguments.kwargs (
Any
) – dictionary of keyword arguments
- Return type:
Optional
[Callable
]- Returns:
Either the function itself or None if an exception was raised during function execution.
Examples
with a function that is executed without any exception:
>>> x = ivy.array([1, 2, 3]) >>> y = ivy.array([4, 5, 6]) >>> z = ivy.try_else_none(ivy.add, x, y) >>> print(z.__name__) add
with a function that is executed with an exception:
>>> x = ivy.array([1, 2, 3]) >>> y = 'hemant' >>> z = ivy.try_else_none(ivy.add,x, y) >>> print(z) None