Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is my BlackBerry exception getMessage() returning null?

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?

like image 446
PaulG Avatar asked Mar 27 '12 14:03

PaulG


People also ask

Why e getMessage() is 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.

Can exception getMessage be null?

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.


1 Answers

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());
}
like image 89
rosco Avatar answered Oct 12 '22 09:10

rosco