以下为《实验14 Java异常处理实验报告》的无排版文字预览,完整格式请下载
下载前请仔细阅读文字预览以及下方图片预览。图片预览是什么样的,下载的文档就是什么样的。
XX***实验报告
实验名称: 实验14 Java异常处理
学生学号: ***01 学生姓名: 朱某某
实验时间: 2021.6.9 实验地点:
实验成绩: 指导教师: 李某某
实验报告基本内容要求:一、实验目的与要求;二、实验内容与原理;三、实验任务;四、程序源代码(核心)与实验结果;五、实验小结与心得
一、实验目的与要求
1.能够正确使用try…catch块处理异常;
2.能够正确使用throws关键字;
3.能够正确定义和使用自定义异常;
二、实验内容与原理
1. try…catch语句块;
2. throws关键字;
3. 自定义异常;
三、实验任务
1.运行以下程序,查看运行结果,如果出现错误的话加以改正:
class TestException
{
public static void main(String args[]) throws Exception
{
System.out.println(“Before Exception”);
int result=new Test().devide(3,1);
System.out.println("the result is:"+result);
System.out.println(“The end of the program”);
}
}
class Test
{
public int devide(int x,int y) throws Exception
{
int result=x/y;
return result;
}
}
2.分析以下程序,分别给出命令行输入参数为以下三种情况时的运行结果。
1)参数为2和0,结果是____ArithmeticException is catched
end of main___________________________________
2)参数为2, 结果是__________ArrayIndexOutOfBoundsException is catched
end of main
_________________________________
3)参数为a, 结果是________java.lang.NumberFormatException: For input string: "a"
end of main____________________________________
public class TestTryCatch2 {
public static void main(String args[]){
args=new String[]{"?","?"};//eclipse中用该句代替命令行输入
try{
int x=Integer.parseInt(args[0]);
int y=Integer.parseInt(args[1]);
int m=x/y;
System.out.println("end of try");
}
catch(ArithmeticException ex){ 内容过长,仅展示头部和尾部部分文字预览,全文请查看图片预览。 .println("the result is:"+result);
System.out.println("The end of the program");
}
}
class Test
{
public int devide(int x,int y) throws Exception
{
int result=x/y;
return result;
}
}
五、实验小结与心得
对于该实验错误的学习,让我能够可以自己更好地去修改代码,自己去解决之前代码的错误之处。可以能够明白java内部结构。让我可以更好地去学习Java。
[文章尾部最后300字内容到此结束,中间部分内容请查看底下的图片预览]请点击下方选择您需要的文档下载。
以上为《实验14 Java异常处理实验报告》的无排版文字预览,完整格式请下载
下载前请仔细阅读上面文字预览以及下方图片预览。图片预览是什么样的,下载的文档就是什么样的。