Skip to content

Commit 6497dda

Browse files
author
Mihail Slavchev
committed
Add unit test for issue #476
1 parent 95d9993 commit 6497dda

5 files changed

Lines changed: 27 additions & 1 deletion

File tree

test-app/app/src/main/assets/app/tests/exceptionHandlingTests.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,6 @@ describe("Tests exception handling ", function () {
280280
}
281281

282282
expect(exceptionCaught).toBe(true);
283-
284283
});
285284

286285
it("should not wrap the thrown exception into NativeScriptException", function () {
@@ -311,4 +310,17 @@ describe("Tests exception handling ", function () {
311310
expect(e2.getCause().getClass()).toBe(java.io.IOException.class);
312311
});
313312

313+
it("should successfully catch Java exception when getStackTrace fails", function () {
314+
var test = new com.tns.tests.ExceptionHandlingTest();
315+
var exceptionCaught = false;
316+
var errMsg;
317+
try {
318+
test.throwException();
319+
} catch (e) {
320+
exceptionCaught = true;
321+
errMsg = e.toString();
322+
}
323+
expect(exceptionCaught).toBe(true);
324+
expect(errMsg).toBe("Error: Unknown error. Cannot get error message.");
325+
});
314326
});
-7.71 KB
Binary file not shown.
21 KB
Binary file not shown.
-44.4 KB
Binary file not shown.

test-app/app/src/main/java/com/tns/tests/ExceptionHandlingTest.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,16 @@
77

88
public class ExceptionHandlingTest
99
{
10+
private static class BadException extends Exception
11+
{
12+
public BadException() {}
13+
14+
@Override
15+
public StackTraceElement[] getStackTrace() {
16+
throw new RuntimeException();
17+
}
18+
}
19+
1020
public void triggerEvent1(String s, int n) throws Exception
1121
{
1222
this.onEvent1(s, n);
@@ -51,4 +61,8 @@ public void getExceptionRec(String s, int n)
5161
{
5262
this.onGetFile(s, n);
5363
}
64+
65+
public void throwException() throws BadException {
66+
throw new BadException();
67+
}
5468
}

0 commit comments

Comments
 (0)