throwexceptiondemo.java
来自「java入门经典教程 java入门经典教程 java入门经典教程」· Java 代码 · 共 29 行
JAVA
29 行
// 例3.2.1 ThrowExceptionDemo.java
class ThrowException
{
public void test(ThrowException te)
{
if ( te == null )
throw new NullPointerException();
else
System.out.println("This Object is not NULL");
}
}
class ThrowExceptionDemo
{
public static void main(String[] args)
{
ThrowException te = new ThrowException();
ThrowException te_null = null;
try
{
te.test(te);
te.test(te_null);
}catch(NullPointerException ne){
System.out.print("Catch Exception: ");
ne.printStackTrace();
}
System.out.println("The program is over");
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?