处理CursorLoader异常 [英] Handle CursorLoader exceptions

查看:268
本文介绍了处理CursorLoader异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个片段实现LoaderManager和使用CursorLoader(没有什么花哨)。我要赶在查询过程中引发的异常,但我不明白如何!任何帮助吗? THX。

I have a Fragment implementing LoaderManager and using CursorLoader (nothing fancy). I want to catch exceptions thrown during the query but I don't see how!!! Any help? Thx.

推荐答案

您将需要从CursorLoader派生去做。事情是这样的:

You would need to derive from CursorLoader to do it. Something like this:

class MyCursorLoader extends CursorLoader {

    public MyCursorLoader(Context context) {
         super(context)
      }

    public CursorLoader(Context context, Uri uri, String[] projection, String selection,
            String[] selectionArgs, String sortOrder) {
        super(context, uri, projection, selection, selectionArgs, sortOrder);
    }

    @Override
    public Cursor loadInBackground() {

        try {
            return (super.loadInBackground);
        } catch (YourException e) {
            // Do your thing.
        }

        return (null);
    }

}

您可以修改它来实现你的错误处理。

You can adapt it to implement your error handling.

这篇关于处理CursorLoader异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆