Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(bridge): return java throwable to node process #104

Merged
merged 6 commits into from
Apr 20, 2024

Conversation

MarkusJx
Copy link
Owner

@MarkusJx MarkusJx commented Apr 14, 2024

Added a new property to each error, called cause which will contain the throwable from the Java process (if present):

import type { JavaError } from 'java-bridge';

try {
    // Call a method that throws an error
    someInstance.someMethodSync();
} catch (e: unknown) {
    const throwable = (e as JavaError).cause;
    throwable.printStackTraceSync();
}

Added a config option called asyncJavaExceptionObjects to control whether the Java throwable should be returned from async contexts. This is required as enabling this option will cause the JavaScript stack trace to be lost. This option is disabled by default.

import { importClass } from 'java-bridge';

const SomeClass = importClass('path.to.SomeClass', {
    asyncJavaExceptionObjects: true,
});

try {
    await SomeClass.someMethod();
} catch (e: unknown) {
    const throwable = (e as JavaError).cause;
    throwable.printStackTraceSync();
}

closes #102

@MarkusJx MarkusJx added the enhancement New feature or request label Apr 14, 2024
@MarkusJx MarkusJx self-assigned this Apr 14, 2024
Signed-off-by: Markus <[email protected]>
@MarkusJx MarkusJx merged commit b0a7fae into main Apr 20, 2024
20 checks passed
@MarkusJx MarkusJx deleted the feat/java-throwable branch April 20, 2024 07:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Access exception objects?
1 participant