# no-unsafe-finally

> Disallow `return`, `throw`, `break`, and `continue` in `finally` blocks

A `finally` block runs after `try` and `catch` have already decided what happens next. A `return`, `throw`, `break`, or `continue` in it overrides that decision. The value that `try` returned is dropped, and an error that was on its way to the caller disappears.

This rule is on by default.

{/* Generated by src/codegen/lint-rule-docs.ts. Do not edit this section. */}

## Configure

On by default as an error. To turn it off:

```toml bunfig.toml
[lint.rules]
"no-unsafe-finally" = "off" # or "warn"
```

{/* End of the generated section. */}

## Examples

Reported. This function always returns `{}`, even when `readConfig()` throws:

{/* bad */}
```js
function load() {
  try {
    return readConfig();
  } finally {
    return {};
  }
}
```

Not reported:

{/* good */}
```js
function load() {
  try {
    return readConfig();
  } finally {
    closeFile();
  }
}
```

A statement that stays inside the `finally` block is fine, such as a `continue` for a loop in the block or a `return` in a nested function:

{/* good */}
```js
try {
  save();
} finally {
  for (const handle of handles) {
    if (!handle.isOpen) continue;
    handle.close();
  }
  log(handles.map(handle => {
    return handle.name;
  }));
}
```
