<!--
{
  "availability" : [
    "iOS: 2.0.0 -",
    "iPadOS: 2.0.0 -",
    "macCatalyst: 13.0.0 -",
    "macOS: 10.0.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/NSSetUncaughtExceptionHandler(_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Function",
  "symbol" : {
    "kind" : "Function",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:@F@NSSetUncaughtExceptionHandler"
  },
  "title" : "NSSetUncaughtExceptionHandler(_:)"
}
-->

# NSSetUncaughtExceptionHandler(_:)

Changes the top-level error handler.

```
func NSSetUncaughtExceptionHandler(_: ((NSException) -> Void)?)
```

## Discussion

Sets the top-level error-handling function where you can perform last-minute logging before the program terminates.

## See Also

[`NSGetUncaughtExceptionHandler()`](/documentation/Foundation/NSGetUncaughtExceptionHandler())

Returns the top-level error handler.

  <doc://com.apple.documentation/documentation/AppKit/NSApplication/reportException(_:)>



---

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)