From b927b28e7d464824d0bcb0e5bda2f2e012e903fb Mon Sep 17 00:00:00 2001 From: Alexey Andreev Date: Tue, 11 Apr 2023 13:42:14 +0200 Subject: [PATCH] js: fix extracting exception message from Java --- .../org/teavm/backend/javascript/runtime.js | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/core/src/main/resources/org/teavm/backend/javascript/runtime.js b/core/src/main/resources/org/teavm/backend/javascript/runtime.js index 0be7d40f7..92ac93071 100644 --- a/core/src/main/resources/org/teavm/backend/javascript/runtime.js +++ b/core/src/main/resources/org/teavm/backend/javascript/runtime.js @@ -714,14 +714,18 @@ if (typeof Reflect === 'object') { }, message: { get: function() { - var javaException = this[$rt_javaExceptionProp]; - if (typeof javaException === 'object') { - var javaMessage = $rt_throwableMessage(javaException); - if (typeof javaMessage === "object") { - return javaMessage.toString(); + try { + var javaException = this[$rt_javaExceptionProp]; + if (typeof javaException === 'object') { + var javaMessage = $rt_throwableMessage(javaException); + if (typeof javaMessage === "object") { + return javaMessage !== null ? javaMessage.toString() : null; + } } + return this[defaultMessage]; + } catch (e) { + return "Exception occurred trying to extract Java exception message: " + e } - return this[defaultMessage]; } } });