<!--
{
  "availability" : [

  ],
  "documentType" : "symbol",
  "framework" : "XCTest",
  "identifier" : "/documentation/XCTest/XCTest/tearDownWithError()",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "XCTest"
    ],
    "preciseIdentifier" : "c:objc(cs)XCTest(im)tearDownWithError:"
  },
  "title" : "tearDownWithError()"
}
-->

# tearDownWithError()

Provides an opportunity to perform cleanup and to throw errors after each test method in a test case ends.

```
func tearDownWithError() throws
```

## Discussion

After each test completes, `XCTest` calls [`tearDown()`](/documentation/XCTest/XCTest/tearDown()), then `tearDownWithError()`, followed by [`tearDown(completion:)`](/documentation/XCTest/XCTest/tearDown(completion:)).

If state cleanup might throw errors, override this method or [`tearDown(completion:)`](/documentation/XCTest/XCTest/tearDown(completion:)). `XCTest` marks the test failed when it catches errors, or skipped when it catches `XCTSkip`.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)