You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/guide/error-handling.md
+14-12Lines changed: 14 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,48 +4,48 @@ title: Error handling
4
4
5
5
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).
6
6
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
8
10
9
-
-**development mode**
10
11
**Allow app crash**: Throw exceptions as soon as an error occurs and crash the app.
11
12
12
13
```ts
13
14
const errorHandler:TraceErrorHandler= {
15
+
14
16
handlerError(err) {
15
-
16
17
throwerr
17
-
18
18
}
19
19
}
20
20
```
21
-
-**development mode**
22
21
23
22
**Prevent app crash**: Write the error message to the console and continue the execution of the app.
24
23
25
24
```ts
26
25
const errorHandler:TraceErrorHandler= {
26
+
27
27
handlerError(err) {
28
-
29
-
Trace.write(err, 'unhandled-error', type.error)
30
-
28
+
Trace.write(err, 'unhandled-error', type.error)
31
29
}
32
30
}
33
31
```
34
-
-**production mode**
32
+
33
+
## Production Mode
35
34
36
35
**Prevent app crash**: For example, send an error report to an analytics server but continue app execution.
37
36
38
37
```ts
39
38
const errorHandler:TraceErrorHandler= {
39
+
40
40
handlerError(err) {
41
-
42
-
reportToAnalytics(err)
41
+
reportToAnalytics(err)
43
42
}
44
43
}
45
44
```
45
+
46
46
For more details about the `TraceErrorHandler`, see the [Tracing in NativeScript](/guide/nativescript-core/tracing) page.
47
47
48
-
###Disabling rethrowing of uncaught JS exceptions to native
48
+
## Disabling rethrowing of uncaught JS exceptions to native
49
49
50
50
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.
51
51
@@ -63,7 +63,9 @@ android: {
63
63
64
64
},
65
65
```
66
+
66
67
To handle discarded exceptions, two options are available:
68
+
67
69
- Listening to the `Application.discardedErrorEvent` and using the received `DiscardedErrorEventData` instance
0 commit comments