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

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

## Declaration

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

## Return Value

Return Value The instance of E that was thrown by expression and is equal to error.

## Overview

Overview note: An instance of ExpectationFailedError if expression does not throw a matching error. The error thrown by expression is not rethrown. Use this overload of #require() when the expression expression should throw a specific error: try #require(throws: EngineFailureError.batteryDied) {   FoodTruck.shared.engine.batteryLevel = 0   try FoodTruck.shared.engine.start() } If expression does not throw an error, or if it throws an error that is not equal to error, an Issue is recorded for the test that is running in the current task and an instance of ExpectationFailedError is thrown. Any value returned by expression is discarded. note: If you use this macro with a Swift compiler version lower than 6.1, it doesn’t return a value. If the thrown error need only be an instance of a particular type, use require(throws:_:sourceLocation:performing:) instead.

## 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(_:sourceLocation:performing:throws:)](testing/require(_:sourcelocation:performing:throws:).md)
