📜  Java Throw Throws 关键字 - Java 代码示例

📅  最后修改于: 2022-03-11 14:52:03.991000             🧑  作者: Mango

代码示例1
//f a method does not handle a checked exception, the method must declare it using the throws keyword. The throws keyword appears at the end of a method's signature. 
One can throw an exception, either a newly instantiated one or an exception that you just caught, by using the throw keyword. 
Understand the difference between throws and throw keywords, throws is used to postpone the handling of a checked exception and throw is used to invoke an exception explicitly. 
Example
import java.io.*;
public class className {

   public void deposit(double amount) throws RemoteException {
      // Method implementation
      throw new RemoteException();
   }
   // Remainder of class definition
}