📄 nullexceptiondemo.java
字号:
class Car
{
void startengine(){};
}
public class NullExceptionDemo{
Car mycar;
void start() throws InstantNotInitException{
if (mycar==null) throw new InstantNotInitException("mycar is null");
mycar.startengine();}
public static void main(String args[]){
NullExceptionDemo demo=new NullExceptionDemo();
try{
demo.start();
System.out.println("start car");
return;
}catch(InstantNotInitException e){
System.out.println("Got exception:"+e.getMessage()); }}
}
class InstantNotInitException extends Exception{
public InstantNotInitException(){}
public InstantNotInitException(String message) {super(message);}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -