Java 中 throw 和 throws 關鍵字有什麼區別?
throw 關鍵字用於顯式引發異常。
示例
public class Test {
public static void main(String[] args) {
throw new NullPointerException();
}
}執行緒“main”java.lang.NullPointerException 中的異常 at a6.dateAndTime.Test.main(Test.java:5)
Java 中的 throws 關鍵字用於推遲處理受檢異常。
public class Test {
public static void main(String[] args)throws NullPointerException {
throw new NullPointerException();
}
}
廣告
資料結構
網路
RDBMS
作業系統
Java
IOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP