代码片
.
public class Demo1 {
/*public static void speak() throws MyException{
Scanner sc=new Scanner(System.in);
int m=sc.nextInt();
if(m>1000){
throw new MyException("m大于1000");
}else{
throw new MyException("m小于1000");
}
}
public static void main(String[] args) {
try {
speak();
} catch (MyException e) {
// TODO Auto-generated catch block
System.out.println(e);
}
}*/
//同时抛出两种异常
/*public static void speak() throws MyException,Exception{
Scanner sc=new Scanner(System.in);
int m=sc.nextInt();
if(m>1000){
throw new MyException("m大于1000");
}else{
throw new Exception();
}
}
public static void main(String[] args)
{
try {
speak();
} catch (Exception e) {
// TODO Auto-generated catch block
System.out.println(e);
}
}
}*/
public static void speak() throws MyException{
Scanner sc=new Scanner(System.in);
int m=sc.nextInt();
int n=sc.nextInt();
if(m/n>10){
throw new MyException("m/n大于10");
}
}
public static void main(String[] args)
{
try {
speak();
} catch (MyException e) {
// TODO Auto-generated catch block
System.out.println(e);
}
catch(ArithmeticException e){
System.out.println("ArithmeticException:除数不能为零");
}catch(Exception e){
System.out.println("其他异常");
}
}
}