From 36edba382db5f80b216e579e63c0f8879145199c Mon Sep 17 00:00:00 2001 From: ruanyf Date: Wed, 8 Jun 2016 09:02:42 +0800 Subject: [PATCH] =?UTF-8?q?docs(async):=20async=20=E8=AF=AD=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/async.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/docs/async.md b/docs/async.md index 0c9bdce..de79809 100644 --- a/docs/async.md +++ b/docs/async.md @@ -877,6 +877,21 @@ f() // hello world ``` +另一种方法是`await`后面的Promise对象再跟一个`catch`方面,处理前面可能出现的错误。 + +```javascript +async function f() { + await Promise.reject('出错了') + .catch(e => console.log(e)); + return await Promise.resolve('hello world'); +} + +f() +.then(v => console.log(v)) +// 出错了 +// hello world +``` + (4)如果`await`后面的异步操作出错,那么等同于`async`函数返回的Promise对象被`reject`。 ```javascript