---
title: "require(_:sourceLocation:performing:throws:)"
framework: testing
role: symbol
role_heading: Macro
path: "testing/require(_:sourcelocation:performing:throws:)"
---

# require(_:sourceLocation:performing:throws:)

Check that an expression always throws an error matching some condition, and throw an error if it does not.

## Declaration

```swift
@discardableResult @freestanding(expression) macro require<R>(_ comment: @autoclosure () -> Comment? = nil, sourceLocation: SourceLocation = #_sourceLocation, performing expression: () async throws -> R, throws errorMatcher: (any Error) async throws -> Bool) -> any Error
```

## See Also

### Checking that errors are thrown

- [Testing for errors in Swift code](testing/testing-for-errors-in-swift-code.md)
- [expect(throws:_:sourceLocation:performing:)](testing/expect(throws:_:sourcelocation:performing:)-1hfms.md)
- [expect(throws:_:sourceLocation:performing:)](testing/expect(throws:_:sourcelocation:performing:)-7du1h.md)
- [expect(_:sourceLocation:performing:throws:)](testing/expect(_:sourcelocation:performing:throws:).md)
- [require(throws:_:sourceLocation:performing:)](testing/require(throws:_:sourcelocation:performing:)-7n34r.md)
- [require(throws:_:sourceLocation:performing:)](testing/require(throws:_:sourcelocation:performing:)-4djuw.md)
