Skip to content

chore: Update cocoa examples to be easier to use #13878

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions platform-includes/capture-error/apple.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,16 @@ You can capture errors with the `captureError` method. This method takes an `Err
```swift {tabTitle:Swift}
import Sentry

enum MyCustomError: Error {
case myFirstIssue
}

func thisFunctionThrows() throws {
throw MyCustomError.myFirstIssue
}

do {
try aMethodThatMightFail()
try thisFunctionThrows()
} catch {
SentrySDK.capture(error: error)
}
Expand All @@ -13,8 +21,18 @@ do {
```objc {tabTitle:Objective-C}
@import Sentry;

- (void)thisFunctionReturnsAnError:(NSError **)error {
*error = [NSError errorWithDomain:@"com.example.myapp"
code:1001
userInfo:@{
NSLocalizedDescriptionKey: @"Something went wrong."
}];
}

// ... Your code

NSError *error = nil;
[self aMethodThatMightFail:&error]
[self thisFunctionReturnsAnError:&error];

if (error) {
[SentrySDK captureError:error];
Expand Down