Generic Function

XCTAssertThrowsError(_:_:file:line:_:)

Asserts that an expression throws an error.

Declaration

func XCTAssertThrowsError<T>(_ expression: @autoclosure () throws -> T, _ message: @autoclosure () -> String = "", file: StaticString = #file, line: UInt = #line, _ errorHandler: (Error) -> Void = { _ in })

Parameters

expression

An expression that can throw an error.

message

An optional description of the failure.

file

The file in which failure occurred. Defaults to the file name of the test case in which this function was called.

line

The line number on which failure occurred. Defaults to the line number on which this function was called.

errorHandler

An optional handler for errors that are thrown by expression.