I'm using the following line of code in all of my catch statements to print errors to the console:
System.out.println("ERROR MESSAGE " + e.getMessage() );
Sometimes, in the console, I get the following:
ERROR MESSAGE null
How can it be null? If it reaches the catch that means an exception was thrown, but why null?
You are catching a different exception to the one that your code is explicitly creating and throwing1. The exception that you are catching doesn't have a message. You need to log the entire exception, not just the exception's message.
The getMessage() method of Throwable class is used to return a detailed message of the Throwable object which can also be null. One can use this method to get the detail message of exception as a string value.
I don't know why it is null, I just suppose that BlackBerry OS and API has a lot of undesired behaviour. I solved this issue by using
e.toString()
as in:
catch (Exception e)
{
System.out.println("Exception caught: " + e.toString());
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With