我很确定之前有效,但是eclipse说它在抛出线上有错误.
try{}
}catch(Exception e){
throw e; }
Run Code Online (Sandbox Code Playgroud)
在我的旧学生项目中,我写道:
try {
Class.forName("org.postgresql.Driver");
this.connection = DriverManager.getConnection(
DataSource.getURL(), DataSource.getUserName(), DataSource.getPassword());
} catch (ClassNotFoundException e) {
System.out.println("Could not find driver to connect to database. Please make"
+ "sure the correseponding postgreSQLjdbc library is added.");
throw e;
} catch (SQLException e) {
System.out.println("Username or password is not correct");
throw e;
}
Run Code Online (Sandbox Code Playgroud)
它很完美.
只有这种类型有效,但它不是我想要的
throw new UnsupportedAddressTypeException();
Run Code Online (Sandbox Code Playgroud)
想必你的方法是宣布抛出UnsupportedAddressTypeException,但不SQLException和ClassNotFoundException.只能从声明它们抛出这些异常或超类的方法抛出已检查的异常(包括重新抛出现有的异常).
| 归档时间: |
|
| 查看次数: |
487 次 |
| 最近记录: |