[Android] 3-7 SQLite基礎 - 基礎API - 2最後提到SQLite的exception並不是強制要加

但是當有錯誤時還是會造成APP的crush

這篇就以最簡單的方法介紹SQLite的exception使用

 

1. 先到官網查看SQLite的exeception, 可以明顯看到最上層的父類別是SQLiteException

http://developer.android.com/reference/android/database/sqlite/SQLiteException.html

 

2. 在程式裡使用的基本型態如下

  try{
   
  }catch(SQLiteException e){
   e.printStackTrace();
  }

 

3. 然後把SQLite的相關code放入就可以了

  try{
   
   db.execSQL("這是錯誤的輸");
   
  }catch(SQLiteException e){
   e.printStackTrace();
  } 

 

 

文章標籤
全站熱搜
創作者介紹
創作者 RX1226 的頭像
RX1226

給你魚竿

RX1226 發表在 痞客邦 留言(0) 人氣(506)