---
title: "closeAfter(_:)"
framework: system
role: symbol
role_heading: Instance Method
path: "system/filedescriptor/closeafter(_:)"
---

# closeAfter(_:)

Runs a closure and then closes the file descriptor, even if an error occurs.

## Declaration

```swift
func closeAfter<R>(_ body: () throws -> R) throws -> R
```

## Parameters

- `body`: The closure to run. If the closure throws an error, this method closes the file descriptor before it rethrows that error.

## Return Value

Return Value The value returned by the closure.

## Discussion

Discussion If body throws an error or an error occurs while closing the file descriptor, this method rethrows that error.

## See Also

### Closing a File

- [close()](system/filedescriptor/close().md)
