Array.fromAsyncadvancedtry {
const arr = await Array.fromAsync([Promise.reject(new Error('oops'))])
} catch (e) {
console.error(e.message) // 'oops'
}Wrap Array.fromAsync() in try/catch to handle rejections from any promise in the iterable.
When using Array.fromAsync, if any promise in the iterable rejects, the entire operation rejects. A try/catch around the await lets you return a fallback value (like null) instead of propagating the error.
This exercise simulates the pattern synchronously: attempt to map each value, returning null if any mapper throws.
Challenge: Implement safeCollect that takes an array of numbers and an optional flag. When shouldFail is true, return null; otherwise return the array as-is.
safeCollect([1, 2, 3], false) // β [1, 2, 3]
safeCollect([1, 2, 3], true) // β null