关于异常
import java.io.*;
class ShowFile {
public static void main(String args[])throws IOException {
int i;
FileInputStream fin;
try {
fin=new FileInputStream(args[0]);
} catch(FileNotFoundException exc) {
System.out.println("File Not Found");
return;//它在这里有什么作用呢,为什么不能注释了呢
} catch(ArrayIndexOutOfBoundsException exc) {
System.out.println("Usage: ShowFile File ");
return;//它在这里有什么作用呢,为什么不能注释了呢
}
do{
i=fin.read();
if(i!=-1)System.out.print((char) i);
}while(i!=-1);
fin.close();
}
}
class ShowFile {
public static void main(String args[])throws IOException {
int i;
FileInputStream fin;
try {
fin=new FileInputStream(args[0]);
} catch(FileNotFoundException exc) {
System.out.println("File Not Found");
return;//它在这里有什么作用呢,为什么不能注释了呢
} catch(ArrayIndexOutOfBoundsException exc) {
System.out.println("Usage: ShowFile File ");
return;//它在这里有什么作用呢,为什么不能注释了呢
}
do{
i=fin.read();
if(i!=-1)System.out.print((char) i);
}while(i!=-1);
fin.close();
}
}
...全文
相关推荐
Java 自定义异常和抛出异常
Java 自定义异常和抛出异常的练习demo
ARM异常处理(异常源的分类、异常的响应流程)
介绍什么是异常以及异常的分类,介绍ARM从中断发生的大致响应流程
C++——异常详解
C++——异常详解,看到就是赚到!!!
Java编写异常类练习
1.编写异常类:空异常、年龄低异常、年龄高异常、 工资低异常、工资高异常、身份证非法异常。 2.编写一个员工类: (1)属性: 编号、姓名、年龄、工资、身份证号码、员工人数(10)、员工工资总额(10000)。 (2)构造器: 构造器1:设置编号、年龄、姓名,如果年龄小于18,抛出年龄低异常;如果年龄大于60,抛出年龄高异常;如果姓名为null或为空字符串,抛出空异常。 构造器2:设置工资、设置身份证号码,如果工资低于600,抛出工资低异常; 如果身份证不是18位,抛出身份证非法异常。 (3)方法 增加工资
浅谈python抛出异常、自定义异常, 传递异常
一. 抛出异常 Python用异常对象(exception object)表示异常情况,遇到错误后,会引发异常。如果异常对象并未被处理或捕捉,程序就会用所谓的回溯(Traceback,一种错误信息)终止执行。 raise 语句 Python中的raise 关键字用于引发一个异常,基本上和C#和Java中的throw关键字相同,如下所示: import traceback def throw_error(): raise Exception("抛出一个异常")#异常被抛出,print函数无法执行 print("飞天猪") throw_error() #运行结果: '''Traceb


Java SE

