Skip to content

Commit 37ddc8f

Browse files
committed
chore: improve error handling
1 parent 11c2d41 commit 37ddc8f

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

content/guide/error-handling.md

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,48 +4,48 @@ title: Error handling
44

55
Errors in NativeScript are handled differently to how they operate in a web app. By default when an unhandled exception is thrown in NativeScript, the app may crash, and an error with the corresponding stack trace will be shown. When the app is in **development** mode this may be the desired behaviour. However, when the app is in **production** an app crash can seriously hurt an app's credibility and drive away customers. In many cases, you'll want different error handling behavior between development and production (e.g. app freeze, blank screen, failed navigation).
66

7-
NativeScript allows error handling to be set dependent on whether the app is in **development** or **production** mode in the following three ways:
7+
NativeScript allows error handling to be set dependent on whether the app is in **Development** or **Production** mode in the following three ways:
8+
9+
## Development Mode
810

9-
- **development mode**
1011
**Allow app crash**: Throw exceptions as soon as an error occurs and crash the app.
1112

1213
```ts
1314
const errorHandler: TraceErrorHandler = {
15+
1416
handlerError(err) {
15-
1617
throw err
17-
1818
}
1919
}
2020
```
21-
- **development mode**
2221

2322
**Prevent app crash**: Write the error message to the console and continue the execution of the app.
2423

2524
```ts
2625
const errorHandler: TraceErrorHandler = {
26+
2727
handlerError(err) {
28-
29-
Trace.write(err, 'unhandled-error', type.error)
30-
28+
Trace.write(err, 'unhandled-error', type.error)
3129
}
3230
}
3331
```
34-
- **production mode**
32+
33+
## Production Mode
3534

3635
**Prevent app crash**: For example, send an error report to an analytics server but continue app execution.
3736

3837
```ts
3938
const errorHandler: TraceErrorHandler = {
39+
4040
handlerError(err) {
41-
42-
reportToAnalytics(err)
41+
reportToAnalytics(err)
4342
}
4443
}
4544
```
45+
4646
For more details about the `TraceErrorHandler`, see the [Tracing in NativeScript](/guide/nativescript-core/tracing) page.
4747

48-
### Disabling rethrowing of uncaught JS exceptions to native
48+
## Disabling rethrowing of uncaught JS exceptions to native
4949

5050
Nativescript also allows the prevention of an app crash by disabling rethrowing of uncaught JS exceptions to native. This can be done by setting the `discardUncaughtJsExceptions` property to `true` inside the [nativescript.config.ts](/project-structure/nativescript-config-ts)file.
5151

@@ -63,7 +63,9 @@ android: {
6363

6464
},
6565
```
66+
6667
To handle discarded exceptions, two options are available:
68+
6769
- Listening to the `Application.discardedErrorEvent` and using the received `DiscardedErrorEventData` instance
6870

6971
```ts

0 commit comments

Comments
 (0)