发布网友 发布时间:2022-04-22 22:11
共1个回答
热心网友 时间:2023-07-01 07:47
public class sssss {
public static void main(String[] args) {
System.out.print("Please input an Integer: ");
int value = new Scanner(System.in).nextInt();
try{
if(value < 0){
throw new MyException("My Exception comes!");
}
}catch (MyException myExp){
System.out.println("MyExcepton caugth!");
}
}
}
class MyException extends Exception{
public MyException(String s){
System.out.println("MyException occurs. The value must be greater than ZERO!");
}
}
-----------------------
Please input an Integer: -5
MyException occurs. The value must be greater than ZERO!
MyExcepton caugth!