更改
closeSessionAndThrow要返回的声明,
RemoteException然后在客户端代码中“抛出”调用它的返回结果。
public RemoteException closeSessionAndThrow( ... ) // <-- add return type here throws RemoteException { ... }public <T> T get( ... ) throws RemoteException{ try { ... } catch (final HibernateException e) { throw this.closeSessionAndThrow( ... ); // <-- add "throw" here }}这会诱使编译器认为它将始终抛出从返回的任何异常
closeSessionAndThrow。由于helper方法本身会引发该异常,因此这一秒
throw永远不会起作用。尽管您可以从帮助程序中返回异常,但是当有人忘记
throw在调用之前添加时,这会引发错误。



