Java 中 throw 和 throws 關鍵字之間有什麼區別?
throw 關鍵字用於顯式引發異常。
示例
public class Test {
public static void main(String[] args) {
throw new NullPointerException();
}
}thread "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