Vb.net 在While循环中尝试捕捉

Vb.net 在While循环中尝试捕捉,vb.net,sqlite,try-catch,while-loop,system.data.sqlite,Vb.net,Sqlite,Try Catch,While Loop,System.data.sqlite,我有一个SQLite数据库,我希望从中读取记录,并针对每个记录执行一段代码 我使用了一个While循环,里面有一个Try-Catch 代码如下:- result = slcom.ExecuteReader() 'TODO: There is a problem with this while loop whereby if an ex is caught the connection ' to the databa

我有一个SQLite数据库,我希望从中读取记录,并针对每个记录执行一段代码

我使用了一个While循环,里面有一个Try-Catch

代码如下:-

            result = slcom.ExecuteReader()
            'TODO: There is a problem with this while loop whereby if an ex is caught the connection
            '      to the database is closed.
            While result.Read
                Try

                       < do some stuff here >

                Catch ex As Exception
                    incrementFailoverCount(result("fid"))
                End Try
            End While
            result.Close()
result=slcom.ExecuteReader()
'TODO:这个while循环有一个问题,如果捕获到一个ex,则连接将被中断
'数据库的连接已关闭。
当结果显示时,请阅读
尝试
<在这里做些事情>
特例
递增故障超支(结果(“fid”))
结束尝试
结束时
结果关闭()
问题是,一旦输入Try块并捕获ex,while循环的下一次迭代就会失败,因为似乎在捕获ex的那一刻,到SQLite数据库的连接就关闭了,尽管连接属性声明它是打开的


有什么想法吗?

您可以将Try Catch中的所有代码移动到一个函数中,该函数返回一个布尔值,并将ByRef参数作为函数的结果


该函数返回值用作操作成功或失败的指示器,即是否引发异常。

实际异常是什么?代码第一次进入循环时,这是正常的。然后,当调用异常时,下一次循环while result.Read生成“Connection was closed,statement was terminated”错误。现在通过将数据预加载到DataTable中对其进行排序。