Skip to content

Commit 192829f

Browse files
authored
ref(native): capture-error using high-level API. (#5085)
1 parent a18ca2e commit 192829f

File tree

1 file changed

+18
-11
lines changed

1 file changed

+18
-11
lines changed

src/includes/capture-error/native.mdx

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,30 @@
11
To capture an error or exception condition, create events containing an
2-
exception object. It needs to contain at least a value and type:
2+
exception object:
33

44
```cpp
55
#include <sentry.h>
66

7-
sentry_value_t exc = sentry_value_new_object();
8-
sentry_value_set_by_key(exc, "type", sentry_value_new_string("Exception"));
9-
sentry_value_set_by_key(exc, "value", sentry_value_new_string("Error message."));
7+
sentry_value_t event = sentry_value_new_event();
8+
9+
sentry_value_t exc = sentry_value_new_exception("Exception", "Error message.");
10+
sentry_event_add_exception(event, exc);
1011

11-
sentry_value_t exceptions = sentry_value_new_object();
12-
sentry_value_t values = sentry_value_new_list();
12+
sentry_capture_event(event);
13+
```
1314
14-
sentry_value_set_by_key(exceptions, "values", values);
15-
sentry_value_append(values, exc);
15+
The above exception does not contain a stack trace, which must be added separately:
16+
17+
```cpp
18+
#include <sentry.h>
1619
1720
sentry_value_t event = sentry_value_new_event();
18-
sentry_value_set_by_key(event, "exception", exceptions);
21+
22+
sentry_value_t exc = sentry_value_new_exception("Exception", "Error message.");
23+
24+
sentry_value_t stacktrace = sentry_value_new_stacktrace(NULL, 0);
25+
sentry_value_set_by_key(exc, "stacktrace", stacktrace);
26+
27+
sentry_event_add_exception(event, exc);
1928
2029
sentry_capture_event(event);
2130
```
22-
23-
This exception does not contain a stack trace, which must be added separately.

0 commit comments

Comments
 (0)