captureException function captures an exception or error and sends it to Sentry.
Function Signature
Parameters
unknown
required
The exception to capture. Can be an Error object, string, or any value.
CaptureContext
Additional context for the exception. Can be:
- A Scope object
- A partial ScopeContext object
- A callback function receiving the current scope
Returns
string
The unique ID of the captured event.
Basic Usage
With Context
Using Object Context
Using Scope Callback
Advanced Examples
With User Context
With Fingerprinting
Control how errors are grouped in Sentry:With Attachments
Implementation Details
Frompackages/core/src/client.ts:
Event Processing
Exceptions go through several processing steps:- Duplicate Check: Ensures the same error object isn’t captured twice
- Event Creation: Converts the exception into an event
- Scope Application: Applies scope data (breadcrumbs, tags, context)
- Event Processors: Runs through event processors
- Sampling: Applies sample rate
- beforeSend: Runs the beforeSend callback
- Transport: Sends to Sentry via transport