問題文
An async function awaits a call that rejects. The surrounding code needs to handle the failure. Which construct handles it?
選択肢
- A try block around the await, with the failure handled in the matching catch block.
- A window level error listener, which is the intended place for handling rejections of any kind.
- An outer try block placed around the call that starts the async function without awaiting it, because the rejection travels up the call stack of the caller in the same way an ordinary exception does.
- An if statement that compares the awaited result of the call against undefined, because a rejected call evaluates to undefined instead of throwing an error object.