MCPcopy Create free account
hub / github.com/codenameone/CodenameOne / stringifyThrowable

Function stringifyThrowable

Ports/JavaScriptPort/src/main/webapp/port.js:419–488  ·  view source on GitHub ↗
(throwable)

Source from the content-addressed store, hash-verified

417}
418
419function* stringifyThrowable(throwable) {
420 if (!throwable || !throwable.__class) {
421 if (throwable == null) {
422 return "null";
423 }
424 return String(throwable);
425 }
426 const className = String(throwable.__class || "java_lang_Throwable");
427 const pieces = [className];
428 if (throwable.message) {
429 pieces.push("jsMessage=" + String(throwable.message));
430 }
431 if (throwable.cn1_java_lang_Throwable_detailMessage && throwable.cn1_java_lang_Throwable_detailMessage.__class === "java_lang_String") {
432 try {
433 pieces.push("detail=" + jvm.toNativeString(throwable.cn1_java_lang_Throwable_detailMessage));
434 } catch (_err) {
435 // Best effort diagnostic path only.
436 }
437 }
438 try {
439 const toStringMethod = jvm.resolveVirtual(throwable.__class, "cn1_s_toString_R_java_lang_String");
440 const value = yield* cn1_ivAdapt(toStringMethod(throwable));
441 if (value && value.__class === "java_lang_String") {
442 pieces.push(jvm.toNativeString(value));
443 }
444 } catch (_err) {
445 // Best effort diagnostic path only.
446 }
447 try {
448 const messageMethod = jvm.resolveVirtual(throwable.__class, "cn1_s_getMessage_R_java_lang_String");
449 const message = yield* cn1_ivAdapt(messageMethod(throwable));
450 if (message && message.__class === "java_lang_String") {
451 pieces.push("message=" + jvm.toNativeString(message));
452 }
453 } catch (_err) {
454 // Best effort diagnostic path only.
455 }
456 // Read the cached stack-trace string when ``Throwable.fillInStack``
457 // populated it (rare in this port — the Codename One ``Throwable``
458 // constructors don't call ``fillInStack``). Skip the fresh
459 // ``new Error().stack`` fallback: the giant per-exception stack dump
460 // it produced was useful once, for the bindCrashProtection diagnosis,
461 // but it's far too noisy to keep on. With the targeted
462 // instrumentation now in ``Log.bindCrashProtection`` we don't need
463 // every Log.e call to ship its caller stack any more.
464 try {
465 const stackField = throwable.cn1_java_lang_Throwable_stack;
466 if (stackField && stackField.__class === "java_lang_String") {
467 const stackText = jvm.toNativeString(stackField);
468 if (stackText) {
469 pieces.push("stack=" + stackText);
470 }
471 }
472 } catch (_err) {
473 // Best effort diagnostic path only.
474 }
475 const cause = throwable.cn1_java_lang_Throwable_cause;
476 if (cause && cause.__class) {

Callers 5

port.jsFile · 0.85
runCn1ssResolvedTestFunction · 0.85

Calls 5

pushMethod · 0.65
keysMethod · 0.65
joinMethod · 0.65
sliceMethod · 0.65
StringClass · 0.50

Tested by

no test coverage detected