开发者

Rethrowing an exception in Android

开发者 https://www.devze.com 2023-02-05 00:30 出处:网络
I\'m developing an Android 2.2 application. I want to catch and re throw the same exception. I want to do this because I have 开发者_运维问答to close a cursor before exit the method (a finally statem

I'm developing an Android 2.2 application.

I want to catch and re throw the same exception. I want to do this because I have 开发者_运维问答to close a cursor before exit the method (a finally statement, isn't it?)

Can I do that? How?

Thanks


If this is just to close the cursor correctly, you can do a try...finally without a catch. That would be something like that :

Cursor cursor = null;
try {
    // initialize and do things with the cursor
} finally {
    if (cursor != null) {
        cursor.close();
    }
}

Alternatively, if you're in an activity, you can use startManagingQuery; which will take care of your cursor lifecycle depending on the activity lifecycle.


Without discussing if this is a good practice you can do this:

throw new YourException();
0

精彩评论

暂无评论...
验证码 换一张
取 消