Function to safely execute a callback function, if the function throws the provided default value will be returned.
Callback function be wrapped with an exception
The default value to return when an exception is thrown
The result of the callback function or the default if an exception occurred calling the callback function.
0.9.5
let theExpression = "{ invalid: json value";let result = safeGet(() => { return JSON.parse(theExpression);}, {});// result === {}; Copy
let theExpression = "{ invalid: json value";let result = safeGet(() => { return JSON.parse(theExpression);}, {});// result === {};
Function to safely execute a callback function, if the function throws the provided default value will be returned.