OOP习题(12)

一、判断题

1、If you are not interested in the contents of an exception object, the catch block parameter may be omitted.。

T        F

解析:T。在某些情况下,当捕获异常时,您可能对异常对象内部的具体信息不感兴趣。如果您只关心发生了异常的事实,而不需要访问或使用异常对象本身,您可以省略 catch 块的参数。

2、catch (type p) acts very much like a parameter in a function. Once the exception is caught, you can access the thrown value from this parameter in the body of a catch block.。

T        F

解析:T。在使用特定类型捕获异常时,catch 参数(在这种情况下是 p)实际上就像函数参数一样。它允许您在 catch 块的主体内访问与抛出的异常相关联的值或信息。

3、异常处理的catch{ }语句块必须紧跟try{ }语句块之后,这两个语句之间不能插入另外语句。

T        F

解析:T。异常处理的 catch 块必须紧跟在 try 块之后,但是在它们之间不可以插入其他语句。

4、有如下语句序列

第1行:    int a=1;
第2行:    try{
第3行:       if(a==1) throw(a);
第4行:       a++;
第5行:    }
第6行:    catch(int b){
第7行:       cout << “error! a = ” << b << endl;
第8行:    }

以上语句的第6行有编译错误,只能写成catch(int)。

T        F

解析:F。catch 块可以使用一个参数来捕获异常,也可以不使用参数,只写 catch,这将捕获任何类型的异常,故并不是只能写成catch(int)。

二、单选题

1、One of the major features in C++ is ( ) handling,which is a better way of handling errors.

A.data        B.pointer        C.test        D.exception

解析:D。C++ 中的一个主要特性是异常处理,它是更好的错误处理方式。

2、What is wrong in the following code?

  vector<int> v;
  v[0] = 2.5;

A.The program has a compile error because there are no elements in the vector.

B.The program has a compile error because you cannot assign a double value to v[0].

C.The program has a runtime error because there are no elements in the vector.

D.The program has a runtime error because you cannot assign a double value to v[0].

解析:C。在访问v[0]时发生错误ÿ

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

博学者普克尔特

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值