throwexception.java
来自「针对越来越多的用户喜欢JAVA」· Java 代码 · 共 24 行
JAVA
24 行
public class ThrowException
{
static int chu(int a) throws ArithmeticException
{
if(a==0)
{
ArithmeticException e=new ArithmeticException("除数不能为0");
throw e;
}
return(100/a);
}
public static void main( String args[] )
{
try
{
System.out.println(chu(0));
}
catch(ArithmeticException e)
{
System.out.println(e.getMessage());
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?