<!--
{
  "availability" : [
    "iOS: 7.0.0 -",
    "iPadOS: 7.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.9.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "JavaScriptCore",
  "identifier" : "/documentation/JavaScriptCore/JSContext/exceptionHandler",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Property",
  "symbol" : {
    "kind" : "Instance Property",
    "modules" : [
      "JavaScriptCore"
    ],
    "preciseIdentifier" : "c:objc(cs)JSContext(py)exceptionHandler"
  },
  "title" : "exceptionHandler"
}
-->

# exceptionHandler

A block to be invoked should evaluating a script result in a JavaScript exception being thrown.

```
var exceptionHandler: ((JSContext?, JSValue?) -> Void)! { get set }
```

## Discussion

The block takes the following parameters:

- context: The context in which the exception originates.
- exception: The JavaScript exception thrown.

The default value exception handler block stores its `exception` parameter value into the context’s [`exception`](/documentation/JavaScriptCore/JSContext/exception) property. As a consequence, the default behavior is that unhandled exceptions occurring within a callback from JavaScript to native code are thrown again upon return. Setting this value to `nil` results in all uncaught exceptions being silently consumed.

---

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)