[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

00.png

 

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

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

01.png

 

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

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

02.png  

 

arrow
arrow

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