c#异常处理_C#异常处理能力问题和解答 套装4

c#异常处理

1) Which is not a valid keyword used in the context of exception handling?
  1. try

  2. catch

  3. final

  4. finally

Answer & Explanation

Correct answer: 3
final

The final keyword is not used to handle exceptions in C#.NET.

1)在异常处理的上下文中使用哪个无效关键字?
  1. 尝试

  2. 抓住

  3. 最后

  4. 最后

答案与解释

正确答案:3
最后

final关键字不用于处理C#.NET中的异常。

2) Which is a valid keyword used in the context of exception handling?
  1. through

  2. throw

  3. final

  4. caught

Answer & Explanation

Correct answer: 2
throw

The throw is a valid keyword used in exception handling.

2)在异常处理的上下文中使用哪个有效关键字?
  1. 通过

  2. 最后

  3. 抓住

答案与解释

正确答案:2

throw是异常处理中使用的有效关键字。

3) There are following statements are given below, which is correct about throw in C#.NET?
  1. The throw keyword is not supported in C#.NET

  2. The throw keyword is used to throw an exception object programmatically

  3. The throw keyword is used in older versions of the .NET framework

  4. The throw keyword is mandatory to use with the try block

Answer & Explanation

Correct answer: 2
The throw keyword is used to throw an exception object programmatically

The 2nd statement is correct about throw keyword.

3)下面给出以下语句,关于C#.NET中的抛出正确吗?
  1. C#.NET不支持throw关键字

  2. throw关键字用于以编程方式引发异常对象

  3. throw关键字在.NET Framework的较旧版本中使用

  4. throw关键字必须与try块一起使用

答案与解释

正确答案:2
throw关键字用于以编程方式引发异常对象

关于throw关键字的第二条语句是正确的。

4) What is the correct output of the given code snippet?
using System;

namespace my_namespace
{
    class program
    {
        static void Main(string[] args)
        {
            int a = 0;
            int b = 10;
            int c = 0;

            try
            {
                c = b / a;
            }
            catch (DivideByZeroException d)
            {
                Console.WriteLine("Divide by zero exception occurred");
            }
        }
    }
}

  1. Divide by zero exception occurred

  2. Syntax error

  3. Linker error

  4. No output

Answer & Explanation

Correct answer: 1
Divide by zero exception occurred

The above code will print "Divide by zero exception occurred" on the console screen.

4)给定代码段的正确输出是什么?
  1. 除零发生异常

  2. 语法错误

  3. 链接器错误

  4. 无输出

答案与解释

正确答案:1
除零发生异常

上面的代码将在控制台屏幕上显示“发生零除零异常”。

5) In the given code snippet finally block will execute or not?
using System;

namespace my_namespace
{
    class program
    {
        static void Main(string[] args)
        {
            int a = 0;
            int b = 10;
            int c = 0;

            try
            {
                c = b / a;
            }
            finally
            {
                Console.WriteLine("Finally executed");
            }
        }
    }
}

  1. Yes, finally will execute

  2. No, finally will not execute

Answer & Explanation

Correct answer: 1
Yes, finally will execute

Yes, finally block will execute.

The output would be,

5)在给定的代码片段中,finally块是否会执行?
 using System ;

namespace my_namespace
{
    class program
    {
        static void Main ( string [ ] args )
        {
            int a = 0 ;
            int b = 10 ;
            int c = 0 ;

            try
            {
                c = b / a ;
            }
            finally
            {
                Console . WriteLine ( " Finally executed " ) ;
            }
        }
    }
}

  1. 是的,最后会执行

  2. 不,最终将无法执行

答案与解释

正确答案:1
是的,最后会执行

是的,finally块将执行。

输出将是

◀ C# Exception Handling Aptitude | Set 4 C# Exception Handling Aptitude | Set 5 ▶
#C#异常处理能力| 设置4 C#异常处理能力| 设置5▶

翻译自: https://www.includehelp.com/dot-net/csharp-exception-handling-aptitude-questions-and-answers-4.aspx

c#异常处理

你可能感兴趣的:(c#异常处理_C#异常处理能力问题和解答 套装4)