1

I have such codes in android studio:

@Override
    public void onLocationChanged(AMapLocation amapLocation) {
        if (amapLocation != null && amapLocation.getAMapException() != null
                && amapLocation.getAMapException().getErrorCode() == 0) {
            // get location information
            mLocation = amapLocation;
            MyApp.getInstance().getPrefs().Latitude()
                    .put("" + amapLocation.getLatitude());
            MyApp.getInstance().getPrefs().Longitude()
                    .put("" + amapLocation.getLongitude());
        }

    }

The method getAMapException returns an instance of AMapLocException which extends from Exception.

Now android studio shows some tips and I don't know how to handle them. enter image description here

Reports calls to specific methods where the result of the call is ignored and which return an object of type (or subtype of) Throwable. Usually these types of methods are meant as factory methods for exceptions and the result should be thrown.

and I also found the ThrowableResultOfMethodCallIgnored.java file source by google, but i still don't know how to handle it.

Miki
  • 40,887
  • 13
  • 123
  • 202
SDJSK
  • 1,292
  • 17
  • 24

1 Answers1

2

This is simply a warning that you have called a method which returns a Throwable, but you are not actually throwing it.

One solution would be to do the following

Throwable t = amapLocation.getAMapException();
if (t != null) {
    throw t;
}

Of course you do not have to throw the exception. You can choose to either ignore or use it in the conditional as you have.

EJK
  • 12,332
  • 3
  • 38
  • 55
  • but why it need such warning. i mean there must be an ultimate method to handle the Exception without throwing it. if not, the app must be cracked. – SDJSK Dec 31 '15 at 16:14
  • Well it would be on you to provide the exception handling in the app. The warning is just a suggestion that you might be mis-using the method. – EJK Dec 31 '15 at 16:17
  • So does this or does this not answer your question _What is "Throwable Result Of Method Call Ignored" in android studio?_. I believe the first sentence of my answer address that. It would be helpful to others if you could either (a) accept the answer, or (b) indicate in a comment why this does not answer your question. – EJK Jan 01 '16 at 18:24
  • 2
    "i mean there must be an ultimate method to handle the Exception without throwing it." The normal way to use throwables is, as the name implies, throwing them. It looks like you've developed a system where the exception is cached and then it's up to the calling code to check for it later. Android Studio is not built to handle this non-standard usage, and it's probably better to just throw the exception when it happens. – nasch Jan 01 '16 at 21:45