I do not understand why the compiler does not warn me not to catch or throw a SQLException . Here's the situation:
I defined this interface:
public interface GenericDatabaseManager { public void createTables(DataBase model) throws SQLException; }
Then I created this class that implements this interface:
public class SqliteHelper extends SQLiteOpenHelper implements GenericDatabaseManager { @Override public void createTables(DataBase model) throws SQLException {
And finally, I call this SqliteHelper.createTables () here:
public class DatabaseManager extends CoreModule { private boolean createUpdateDB(final String dbString, final String appId) {
dbCoreModel.getManager() returns an instance of GenericDatabaseManager . But the compiler does not show errors in the line dbCoreModel.getManager().createTables(dbModel); although this line throws a SQLException .
Does anyone have an idea why this is happening? Thanks in advance.
EDIT : There is no need to get RuntimeException near SQLException because it has a RuntimeException . This is not true . Here is 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"); } }
In this case, the compiler shows an error in i.throwsSQLException(); .
source share