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