Sunday, August 25, 2013

Variation on AsyncResult for Android AsyncTaskLoader

I found this example of an AsyncResult for an Android AsyncTaskLoader

However, it suggests a pattern of handling exception types with if/else statements in the "if (exception != null)", likely with instanceof.

That responsibility really belongs to the user, and the user can do this instead:

try {
   if (result.getException ()) throw result.getException ();
   // non-exception results
} catch ...

However, this also leaves the responsibility of the user to catch and not ignore the exception. So here's a better alternative that forces the user to catch the (parameterized!) exception to get the value:

No comments:

Post a Comment