exceptiondemo3.java
来自「JAVA程序设计课程中各章节的程序实例。」· Java 代码 · 共 46 行
JAVA
46 行
/**
*A simple exception handling example
*2004.12.25. xhcprince
*/
class ExceptionClass
{
String name = "Bob";
public void show()
{
System.out.println("name is: " + name);
}
}
class exceptionDemo3
{
public static void main(String args[])
{
try
{
int a=4,b=1,c;
c = a/b;
System.out.println("c = " + c);
ExceptionClass obj = null;//new ExceptionClass();
obj.show();
}
catch(ArithmeticException e)
{
System.out.println("Denominator can't be zero");
}
/*catch(NullPointerException e)
{
System.out.println("Null reference has been use to access a member");
}*/
catch(Exception e)
{
System.out.println("Unexpected error");
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?