为什么不赶的SQLException SQLiteExcpetion? [英] Why doesn't SQLException catch SQLiteExcpetion?

查看:152
本文介绍了为什么不赶的SQLException SQLiteExcpetion?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些code在我,捕获的SQLException Android应用程序之一,但我最近发现,它没有赶上SQLiteException的。显然,SQLiteException的SQLException是一个孩子,所以为什么不被抓?下面是一些code我使用。

I have some code in one of my android apps that catches SQLException, but I've recently found that it's not catching SQLiteException's. Clearly, SQLiteException is a child of SQLException, so why isn't it being caught? Here's some code I'm using.

try {
    ... // something here that will throw an SQLiteException
} catch (SQLException e) {
    e.printStackTrace();
}

是我的假设是正确的,我应该抓住SQLiteException?

Is my assumption correct that I should be catching SQLiteException?

如果它在所有重要的,我使用这个code不是一个活动里面,但是它扩展了应用类里面类。

If it matters at all, i'm using this code not inside of an Activity, but inside of a class that extends the Application class.

作为一个方面说明,我并添加一个额外的赶上(例外五){} 来看看是否能够工作,它确实正常工作。

As a side note, I did add an additional catch( Exception e ){} to see if that would work and it did indeed work as expected.

推荐答案

有两种类型的SQLException的:

There are two types of SQLException:

android.database.SQLException
java.sql.SQLException

请确保您使用的是第一的没有第二个。

make sure you are using the first not the second.

这篇关于为什么不赶的SQLException SQLiteExcpetion?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆