📄 userexception.java
字号:
//UserException.java
import java.io.*;
public class UserException
{
//抛出异常的方法
void doSomeThing()
{
int a = 0;
int b = 10;
//产生异常的条件判断
if(a!=0)
{
System.out.println("Normal");
}
else
{
//抛出异常
throw new UserDefineException();
}
}
public static void main(String args[])
{
UserException one = new UserException();
//调用类实例的方法
one.doSomeThing();
}
}
//用户定义的异常,由Exception类派生
class UserDefineException extends ArithmeticException
{
public UserDefineException(){
System.out.println("Exception occured");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -