2011-02-14 111 views
1

我有一個SQLite數據庫,我希望從每條記錄讀取記錄並執行一段代碼。嘗試在while循環內捕獲

我使用了嘗試catch裏面While循環...

代碼如下: -

  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() 

的問題是,一旦進入Try塊與前任是被捕獲,while循環的下一次迭代失敗,因爲它似乎是一個ex被捕獲的時刻,與SQLite數據庫的連接被關閉,儘管連接屬性表明它已打開。

任何想法???

+0

什麼是實際異常? – 2011-02-14 10:12:27

回答

0

您可以將嘗試捕捉內的所有代碼到返回boolean值的功能,並採取了ByRef參數作爲函數

該函數的返回值擔任了成功的指標或失敗的操作,即異常的結果被提出與否。