java异常分析加作业(需要再去看,没看懂)


在这里插入图片描述
在这里插入图片描述
异常处理
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
自定义异常
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
作业
class MultiCatch

{

 public static void main(String args[])

{

    try

    {

          int a=args.length;

          int b=42/a;

          int c[]={1};

          c[42]=99;  //10行

          System.out.println(“b=”+b);

        }

    catch(ArithmeticException e)

    {

            System.out.println(“除0异常:”+e);  //15行

    }

    catch(ArrayIndexOutOfBoundsException e)

    {

            System.out.println(“数组超越边界异常:”+e); //19行

        }

     }    

  }
 **第十五行没问题**
 请问所有的异常(Exception)和错误(Error)类皆继承哪一个类?(    )

得分/总分

A.
java.lang.Throwable

B.
java.lang.Exception

0.00/3.00

C.
java.lang.Error

D.
java.io.Exception

正确答案:A你错选为B
不管Error还是Exception都是Throwable的子类。

import java.io.*;

class Master {

String doFileStuff() throws FileNotFoundException {

    return "a";

}

}

class Slave extends Master {

public static void main(String[] args){

String s = null;

try { 

    s = new Slave().doFileStuff();

}catch ( Exception x){

s = "b"; 

}

System.out.println(s);

}

// insert code here

}

Which, inserted independently at // insert code here, will compile, and produce the output b? (Choose all that apply.)

得分/总分

A.
String doFileStuff() { return “b”; }

B.
String doFileStuff() throws IOException { return “b”; }//新

C.
String doFileStuff(int x) throws IOException { return “b”; }//新,且不是重写

D.
String doFileStuff() throws Exception { return “b”; }//大

选 A

classPlane{

    static String s ="-";

    publicstaticvoidmain(String[] args){

        newPlane().s1();

        System.out.println(s);

    }

    voids1(){

        try{s2();}catch(Exception e){

         s +="c";}

    }

    voids2()throws Exception {

        s3();//直接抛出异常

        s +="2";

        s3();

        s +="2b";

    }

    voids3()throws Exception{

          thrownewException();

    }

}

结果为-c
//会直接抛出异常,下面的代码不会执行

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值