在Android中重新抛出异常

时间:2011-01-13 12:22:09

标签: android try-catch sqlexception

我正在开发Android 2.2应用程序。

我想抓住并重新抛出相同的异常。我想这样做,因为我必须在退出方法之前关闭一个游标(一个finally语句,不是吗?)

我能这样做吗?怎么样?

由于

2 个答案:

答案 0 :(得分:1)

如果这只是为了正确关闭光标,你可以做一个try...finally没有捕获。那将是这样的:

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

或者,如果您参与某项活动,则可以使用startManagingQuery;它将根据活动生命周期来处理您的游标生命周期。

答案 1 :(得分:0)

如果没有讨论这是一个好习惯,你可以这样做:

throw new YourException();