在Android自定义内容提供商中处理(跨进程)异常 [英] Dealing with (cross-process) exceptions in Android custom content provider
问题描述
我应该如何向我的来电显示异常状态?我必须以某种方式将其编码到我的返回数据中,并依靠客户端来检查它吗?有什么办法吗?如果编码成普通的返回数据是什么,最好的方法是什么? (我可以看到查询
调用返回的 Cursor
的一些替代方案,但是$ code> Uri 由插入
或 int
c>更新或删除
?)
p>有一个 RuntimeException
子类的简短列表,如果在提供程序中抛出,将在客户端应用程序中重新抛出。这些是:
-
IllegalStateException
-
IllegalArgumentException
-
NullPointerException
-
SecurityException
-
BadParcelableException
资料来源:创建内容提供商提到 IAE
和 NPE
;我猜其他人会根据 Parcel.writeException
的Javadoc。
客户端应用只会收到详细信息,而不是堆栈跟踪或原因栈。对于可以编码为 String
(详细信息)的特殊状态,这是一个合理的选择。
我仍然对其他解决方案感兴趣。
I have a custom content provider in my Android app that works reasonably well. I expect other apps to also access my content provider. I would like some clean way to communicate exceptions and errors, but as far as I can tell the Android content provider framework doesn't provide any way to propagate exceptions across processes.
How should I indicate an exception state to my caller? Do I have to somehow encode it into my returned data and rely on clients to check for it? Is there any alternative? If encoding into the ordinary return data is it, what's the best way? (I can see a number of alternatives for the Cursor
returned by a query
call, but what about the Uri
returned by insert
, or the int
returned by update
or delete
?)
There is a short list of RuntimeException
subclasses which, if thrown in the provider, will be re-thrown in a client app. These are:
IllegalStateException
IllegalArgumentException
NullPointerException
SecurityException
BadParcelableException
Source: Creating Content Providers mentions IAE
and NPE
; I guessed that the others would work based on the Javadoc forParcel.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.
这篇关于在Android自定义内容提供商中处理(跨进程)异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!