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

Try-catch loses traceback information #726

Open
opeongo opened this issue Feb 22, 2023 · 1 comment
Open

Try-catch loses traceback information #726

opeongo opened this issue Feb 22, 2023 · 1 comment

Comments

@opeongo
Copy link
Contributor

opeongo commented Feb 22, 2023

In the following script the error occurs at line 5.

try {
    /*
     * Trigger an error
     */
    o = (Number) Double.valueOf(1);
} catch (Exception ex) {
    ex.printStackTrace();
}

However the traceback information indicates that the error is at line 1 (the start of the try block):

bsh.EvalError: Sourced file: testCast.bsh unknown error: class java.lang.Double cannot be cast to class bsh.Primitive (java.lang.Double is in module java.base of loader 'bootstrap'; bsh.Primitive is in unnamed module of loader ca.spatial.util._bF @7a9273a8) : at Line: 1 : in file: testCast.bsh : try {

Caused by: Sourced file: testCast.bsh unknown error: class java.lang.Double cannot be cast to class bsh.Primitive (java.lang.Double is in module java.base of loader 'bootstrap'; bsh.Primitive is in unnamed module of loader ca.spatial.util._bF @7a9273a8) : at Line: 1 : in file: testCast.bsh : try {

Caused by: class java.lang.Double cannot be cast to class bsh.Primitive (java.lang.Double is in module java.base of loader 'bootstrap'; bsh.Primitive is in unnamed module of loader ca.spatial.util._bF @7a9273a8)

This loss of traceback information makes it difficult to locate the source of problems. It would be better if the full traceback of all previous chained exceptions was also displayed.

@nickl-
Copy link
Member

nickl- commented Apr 1, 2023

I am confused though, this doesn't look like the output of the printStackTrace.

We have the correct error:

Caused by: class java.lang.Double cannot be cast to class bsh.Primitive (java.lang.Double is in module java.base of loader 'bootstrap'; bsh.Primitive is in unnamed module of loader ca.spatial.util._bF @7a9273a8)

And I am willing to bet it has the correct context too, somewhere we need to unwrap to get to this error. Hence my confusion whether this comes from Exception ex or not. We need to identify where the output comes from first.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants