📄 myexceptionabc.java
字号:
import java.io.*;
class IllegalDataException extends Exception
{
IllegalDataException()
{
System.out.println("发生自定义异常类!!!");
}
}
public class myexceptionabc
{
public static void isIllegalData(int m) throws IllegalDataException
{
if(m>100||m<0)
{
IllegalDataException ae=new IllegalDataException();
throw ae;
}
}
public static void main(String args[])//throws IllegalDataException
{
int a[]={0,0,0,0,0,0,0,0,0,0};
int i=0,temp=-1;
BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
try{ //此处可能会抛出I/O异常
System.out.println("请输入10个整形数据,并且数据值范围为(>=0&&<=100):");
temp=Integer.parseInt(in.readLine()); //此处可能会抛出数据格式异常
while(temp!=0)
{
isIllegalData(temp);
a[i]=temp;
i++;
temp=Integer.parseInt(in.readLine());
}
}
catch(ArrayIndexOutOfBoundsException e)
{
System.out.println("发生数组越界异常!!!");
}
catch(IOException e) //捕获I/O异常并处理
{
System.out.println("I/O error");
}
catch(NumberFormatException e)
{
System.out.println("输入数据类型出错异常,请输入一个数字类型数据!");
}
catch(IllegalDataException e)
{
System.out.println("请输入一个>=0&&<=100的数据!");
}
finally
{
System.out.println("输入结果为:");
for(i=0;i<10;i++)
{
System.out.print(" "+a[i]);
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -