I don't understand why the compiler does not warn me about not catching or throwing an SQLException
. Here's the situation:
I have defined this interface:
public interface GenericDatabaseManager {
public void createTables(DataBase model) throws SQLException;
}
Then I created this class that implements the given interface:
public class SqliteHelper extends SQLiteOpenHelper implements
GenericDatabaseManager {
@Override
public void createTables(DataBase model) throws SQLException {
// Code that throws SQLException
}
And finally I'm calling this SqliteHelper.createTables() from here:
public class DatabaseManager extends CoreModule {
private boolean createUpdateDB(final String dbString, final String appId) {
// Previous code...
if (oldVer == -1) {
dbCoreModel.addModel(dbModel);
dbCoreModel.getManager().createTables(dbModel);
return true;
}
// More code...
}
}
dbCoreModel.getManager()
returns a GenericDatabaseManager
instance. But the compiler shows no error on dbCoreModel.getManager().createTables(dbModel);
line, although this line throws an SQLException
.
Does anyone have an idea about why is this happening? Thanks in advance.
EDIT: about SQLException
does not need to be catched because it's a RuntimeException
. This is not true. Here's an example:
import java.sql.SQLException;
interface Interface {
public void throwsSQLException() throws SQLException;
}
class Test implements Interface {
@Override
public void throwsSQLException() throws SQLException {
throw new SQLException();
}
}
public class Main {
public static void main(String[] args) {
Interface i = new Test();
i.throwsSQLException();
System.out.println("Finished");
}
}
The compiler DOES show an error in i.throwsSQLException();
in this case.
try {
and "More code..." contains a} catch (SQLException e) {
, right ? :D – Grunterjava.sql.SQLException
, butandroid.database.SQLException
. Check yourimport
s. – Grunter