Skip to content

Commit 5b8069b

Browse files
committed
chore: Update cocoa examples to be easier to use
1 parent 4678394 commit 5b8069b

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

platform-includes/capture-error/apple.mdx

Lines changed: 19 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 thisFunctionWillThrow() throws {
11+
throw MyCustomError.myFirstIssue
12+
}
13+
614
do {
7-
try aMethodThatMightFail()
15+
try thisFunctionWillThrow()
816
} catch {
917
SentrySDK.capture(error: error)
1018
}
@@ -13,8 +21,17 @@ do {
1321
```objc {tabTitle:Objective-C}
1422
@import Sentry;
1523

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

1936
if (error) {
2037
[SentrySDK captureError:error];

0 commit comments

Comments
 (0)