dwwilson66
dwwilson66

Reputation: 7076

How and where can I interpret a Java error message of "3" returned from java.lang.String?

I am running a Java program that parses BufferedReader input into a delimited string for output to a file. After successfully reading 24 lines from the source file and saving them to the destination file, I get an error message of 3 (using the getMessage()) method in the catch paired with the "read the next line of the file" try.

When I change the catch to the following,

    catch (Exception e)
    {
        System.err.println("Error: " + e.getMessage().getClass().getName());
    }

the catch results in the Error: java.lang.String being returned...but no further explanation. Bad characters in the file? Inorrect casting? OutOfBounds as another comment suggested? any other ideas how to extract further information from this error?

I have reviewed the input file in a hex editor and there are no unexpected EOF or null characters between the rows, the input data displays as expected in a hex or text editor, and I cannot find any documentation about how to interpret a 3 error message, or even how to determine if it's an OS or Java exception.

Upvotes: 0

Views: 771

Answers (1)

Stephen D
Stephen D

Reputation: 3076

Instead of using e.getMessage(), try using e.printStackTrace(). This will show the full details of the exception and should point you in the right direction.

catch (Exception e)
{
    System.err.print("Error: ");
    e.printStackTrace();
}

You can also try:

catch (Exception e)
{
    System.err.println("Error: " + e);
}

Upvotes: 5

Related Questions