---
url: /docs/guide/usage/linter/rules/promise/catch-or-return.md
---

### 作用

确保每次对 promise 调用 `then()` 时，都必须同时调用 `catch()`。
对于从函数中返回的 promise，则属于例外。

### 为什么这不好？

未捕获 promise 中的错误可能会导致难以调试的问题，或遗漏对错误条件的处理。
在最坏的情况下，未处理的 promise rejection 可能会导致应用崩溃。

### 示例

以下是此规则的**错误**代码示例：

```javascript
myPromise.then(doSomething);
myPromise.then(doSomething, catchErrors); // `catch()` 可能会更好一些
```

以下是此规则的**正确**代码示例：

```javascript
myPromise.then(doSomething).catch(errors);
function doSomethingElse() {
  return myPromise.then(doSomething);
}
const arrowFunc = () => myPromise.then(doSomething);
```

## 配置

此规则接受一个包含以下属性的配置对象：

### allowFinally

type: `boolean`

default: `false`

是否允许将 `finally()` 作为终止方法。

### allowThen

type: `boolean`

default: `false`

是否允许使用带两个参数的 `then()` 作为终止方法。

### allowThenStrict

type: `boolean`

default: `false`

是否允许将 `then(null, handler)` 作为终止方法。

### terminationMethod

type: `array | string`

#### terminationMethod\[n]

type: `string`

## How to use

## 版本

此规则在 v0.9.2 中添加。

## 参考
