throw错误,各位大大能说一下这个throw为什么错误了吗
package homework6;
import java.util.Scanner;
import java.util.InputMismatchException;
public class Test {
public static void main(String[] args) {
try{
foo();
}catch(MyStrChkException e){
System.out.println("触发自定义异常!");
System.out.println(e.getContent());
}catch(InputMismatchException e){
System.out.println("数字格式异常");
}catch(Exception e){
System.out.println("程序结束!");
}
}
public static void foo()throws MyStrChkException{
Scanner input = new Scanner(System.in);
double y, c;
System.out.println("请输入除数");
y=input.nextInt();
if(y==0){
input.close();
throw new MyStrChkException("除数不能为0");
}
c=10/y;
System.out.println("10/y="+c);
input.close();
}
class MyStrChkException extends Exception{
private static final long serialVersionUID=1L;
private String content;
public MyStrChkException(String content){
this.content = content;
}
public String getContent(){
return content;
}
}
}