0

I throw a exception with some message like:

public static ILSResponseEmailLookUPBO getILSUserAccounts(Resources res,
        String email) throws TripLoggerCustomException,
        TripLoggerUnexpectedErrorException {
    String resp = null;

    String lookupURL;
    try {
        lookupURL = TripLoggerConstants.ServerConstants.ILS_LOOKUP_URL
                + URLEncoder.encode(email, "UTF-8");
    } catch (UnsupportedEncodingException e1) {
        throw new TripLoggerCustomException(
                res.getString(R.string.error_try_again));
    }
    try {
        resp = ConnectionManager.getInstance().httpRequest(lookupURL,
                TripLoggerConstants.RequestMethods.GET);
    } catch (IOException e) {
        if (e.getMessage().equals(
                res.getString(R.string.network_unreachable))
                || e.getMessage().equals(
                        res.getString(R.string.host_unresolved))) {
            throw new TripLoggerCustomException(
                    res.getString(R.string.network_not_reachable));
        } else {
            throw new TripLoggerCustomException(
                    res.getString(R.string.email_notfound_ils));
        }
    }

here my else part execute. And my exception class is:

 public class TripLoggerCustomException extends Exception {

    private String customMessage;
    private static final long serialVersionUID = 1L;

    public TripLoggerCustomException() {
        super();
    }

    public TripLoggerCustomException(String message) {
        super(message);
        this.customMessage = (message == null ? "" : message);
    }

    public String getCustomMessage() {
        return this.customMessage;
    }

    public void setCustomMessage(String customMessage) {
        this.customMessage = customMessage;
    }
     }

And here i catch this exception:

  private void manageLookUpActions(final String emailID) {

    new Thread() {
        public void run() {

            try {
                listILSAccounts = ILSLookupEmailBL.getILSUserAccounts(
                        getResources(), emailID);
            } catch (TripLoggerCustomException e) {
                dismissProgressBar();
                handleException(e.getMessage());
                return;
            } catch (TripLoggerUnexpectedErrorException e) {
                dismissProgressBar();
                handleException(e.getMessage());
                return;
            }
}
    }.start();

}

but here in catch of TripLoggerCustomException e is null.why?Can anyone help me?

Hariharan
  • 24,741
  • 6
  • 50
  • 54
user2106897
  • 529
  • 1
  • 5
  • 11
  • 1
    I believe this is impossible. If the exception was null, then the system could never figure out it was of type `TripLoggerCustomException`. Do you get a NullPointer exception in this line: `handleException(e.getMessage());`. Can you try to add a global `} catch (Exception e){}` to see if it ends up there? – Jeffrey Klardie Oct 25 '13 at 08:33
  • @JeffreyKlardie there is not occurred null pointer exception and it exactly enter in TripLoggerCustomException catch block but the issue is "e" is null in catch block of TripLoggerCustomException. – user2106897 Oct 25 '13 at 08:42
  • Well, if `e` really is null then `e.getMessage()` will result in a NullPointerException. I'm pretty sure that there is no way that e is null at that point. – Jeffrey Klardie Oct 25 '13 at 08:47
  • Or do you mean that the message is null? In that case, make sure that the message you pass to the `TripLoggerCustomException` in `getILSUserAccounts()` has a correct text. You could print the content of `res.getString(R.string.error_try_again)` (or one of the other lines where you throw that exception) to your log. – Jeffrey Klardie Oct 25 '13 at 08:48
  • I print that message that is not null but in catch block instance of "e" is null this is main issue – user2106897 Oct 25 '13 at 08:50
  • This is impossible. You can try to eliminate your custom exception, and throw the `UnsupportedEncodingException` and `IOException` and see what happens then. If that works correctly, then there is probably something wrong in your custom Exception (but I don't see what at a first glance). – Jeffrey Klardie Oct 25 '13 at 08:55
  • Yes exactly i throw TripLoggerUnexpectedErrorException and in catch block of TripLoggerUnexpectedErrorException e is not null so there is issue with TripLoggerCustomException but TripLoggerCustomException and TripLoggerUnexpectedErrorException have same integration and this issue is so weird. – user2106897 Oct 25 '13 at 09:02
  • Can you post the full method of `getILSUserAccounts()`, so I can see where you throw it? Also, let the code run completely, and show me the NullPointer from your log. You WILL get a NullPointer if e is null. – Jeffrey Klardie Oct 25 '13 at 09:14
  • More importantly, can you show the `handleException()` method. There might be an issue there. – Jeffrey Klardie Oct 25 '13 at 09:15

1 Answers1

0

After looking into multiple reports on StackOverflow, it seems like this is not an actual issue. Multiple people have been saying that it is a problem in the combination of the Eclipse debugger and the Android Emulator. That is why you don't get a NullPointerException, which you would definitely get if e was null.

So this is probably not an issue you have to worry about.

Community
  • 1
  • 1
Jeffrey Klardie
  • 3,020
  • 1
  • 18
  • 23