Closed. This question needs details or clarity。它当前不接受答案。
                            
                        
                    
                
            
                    
                
                        
                            
                        
                    
                        
                            想改善这个问题吗?添加详细信息并通过editing this post阐明问题。
                        
                        6年前关闭。
                    
                
        

public interface RMIInterface extends Remote {
    public byte[] geScreen() throws RemoteException;
    public byte[] getProcessList() throws RemoteException;
    public boolean execute(String command) throws RemoteException;
    public boolean messageTo(String msg,String user) throws RemoteException;
    public boolean saveImage(byte[] image,String user) throws RemoteException;
    public byte[][] getimages(String user,String date)throws RemoteException;
}


上面的RMI接口方法会抛出RemoteException,如果我尝试将这些方法括起来并捕获RemoteException,那就可以了。

最佳答案

您不能在接口中使用try-catch,因为这里没有实现,只有规范/合同。相反,您可以像已经一样使用throws <exception list>

关于java - 在界面中,每种方法应该使用try-catch还是throws? ,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/17288901/

10-10 19:02