Skip to content

Commit a7146db

Browse files
authored
chore: Update cocoa examples to be easier to use (#13878)
## DESCRIBE YOUR PR Improves the Apple examples so it can be copy pasted to generate the first Sentry issue. Fixes [getsentry/sentry-cocoa#4991](getsentry/sentry-cocoa#4991) ## IS YOUR CHANGE URGENT? Help us prioritize incoming PRs by letting us know when the change needs to go live. - [ ] Urgent deadline (GA date, etc.): <!-- ENTER DATE HERE --> - [ ] Other deadline: <!-- ENTER DATE HERE --> - [x] None: Not urgent, can wait up to 1 week+ ## SLA - Teamwork makes the dream work, so please add a reviewer to your PRs. - Please give the docs team up to 1 week to review your PR unless you've added an urgent due date to it. Thanks in advance for your help! ## PRE-MERGE CHECKLIST *Make sure you've checked the following before merging your changes:* - [x] Checked Vercel preview for correctness, including links - [ ] PR was reviewed and approved by any necessary SMEs (subject matter experts) - [ ] PR was reviewed and approved by a member of the [Sentry docs team](https://github.com/orgs/getsentry/teams/docs) ## LEGAL BOILERPLATE <!-- Sentry employees and contractors can delete or ignore this section. --> Look, I get it. The entity doing business as "Sentry" was incorporated in the State of Delaware in 2015 as Functional Software, Inc. and is gonna need some rights from me in order to utilize my contributions in this here PR. So here's the deal: I retain all rights, title and interest in and to my contributions, and by keeping this boilerplate intact I confirm that Sentry can use, modify, copy, and redistribute my contributions, under Sentry's choice of terms. ## EXTRA RESOURCES - [Sentry Docs contributor guide](https://docs.sentry.io/contributing/)
1 parent 9335ce9 commit a7146db

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

platform-includes/capture-error/apple.mdx

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,16 @@ You can capture errors with the `captureError` method. This method takes an `Err
33
```swift {tabTitle:Swift}
44
import Sentry
55

6+
enum MyCustomError: Error {
7+
case myFirstIssue
8+
}
9+
10+
func thisFunctionThrows() throws {
11+
throw MyCustomError.myFirstIssue
12+
}
13+
614
do {
7-
try aMethodThatMightFail()
15+
try thisFunctionThrows()
816
} catch {
917
SentrySDK.capture(error: error)
1018
}
@@ -13,8 +21,18 @@ do {
1321
```objc {tabTitle:Objective-C}
1422
@import Sentry;
1523

24+
- (void)thisFunctionReturnsAnError:(NSError **)error {
25+
*error = [NSError errorWithDomain:@"com.example.myapp"
26+
code:1001
27+
userInfo:@{
28+
NSLocalizedDescriptionKey: @"Something went wrong."
29+
}];
30+
}
31+
32+
// ... Your code
33+
1634
NSError *error = nil;
17-
[self aMethodThatMightFail:&error]
35+
[self thisFunctionReturnsAnError:&error];
1836

1937
if (error) {
2038
[SentrySDK captureError:error];

0 commit comments

Comments
 (0)