Compiler Error / catch / throwing exception warning

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 { // Code that throws SQLException } 

And finally, I call this SqliteHelper.createTables () 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 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(); .

+6
source share
1 answer

android.database.SQLException - A runtime exception.

In java, there is no need to catch or declare throws for exceptions at runtime. Read a detailed description of RuntimeExceptions in java here

+12
source

All Articles