Get to know MDN better
此頁面由社群從英文翻譯而來。了解更多並加入 MDN Web Docs 社群。
This feature is well established and works across many devices and browser versions. It’s been available across browsers since 2015年7月.
catch() 方法只處理 Promise 的被拒絕狀態,並回傳一個新的 Promise 物件。此方法的行為等同於呼叫 Promise.prototype.then(undefined, onRejected)。
一個 Function ,在 Promise 被拒絕時被呼叫。這個函式有一個引數:
reason失敗訊息。
若 onRejected 拋出一個錯誤或回傳一個被拒絕的 Promise,則 catch() 回傳的 Promise 被拒絕;其他情形都是被實現。
呼叫(catch 的 promise)物件,內部呼叫 Promise.prototype.then,傳入引數 undefined 及 onRejected;接著以之結果回傳(結果為 Promise)。
內部呼叫演示:
catch 方法在處理 promise 組合的錯誤時很有幫助。
| ECMAScript® 2027 Language Specification # sec-promise.prototype.catch |
Enable JavaScript to view this browser compatibility table.
This page was last modified on 2025年7月14日 by MDN contributors.
Your blueprint for a better internet.
Visit Mozilla Corporation’s not-for-profit parent, the Mozilla Foundation.
Portions of this content are ©1998–2026 by individual mozilla.org contributors. Content available under a Creative Commons license.