Dealing with (cross-process) exceptions in Android custom content provider

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-03 06:01:41

There is a short list of RuntimeException subclasses which, if thrown in the provider, will be re-thrown in a client app. These include:

  • IllegalStateException
  • IllegalArgumentException
  • NullPointerException
  • SecurityException
  • BadParcelableException

A more recent update to the Parcel.writeException documentation added

  • UnsupportedOperationException
  • NetworkOnMainThreadException

Source: Creating Content Providers mentions IAE and NPE; I guessed that the others would work based on the Javadoc for Parcel.writeException.

The client app will only get the detail message, not a stack trace or the cause stack. For exceptional state which can be encoded into a String (the detail message), this is a reasonable choice.

I'm still interested in other solutions, too.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!