Exception handling in .NET - placement questions

Exception handling in .NET - placement questions


Q.1 Why should you close and dispose of resources in a Finally block instead of a Catch block?

A) You cannot dispose of resources in a Catch block.
B) Finally blocks run whether or not an exception occurs.
C) The compiler throws an error if resources are not disposed in the Finally block.
D) None of the above.

View Answer / Hide Answer

ANSWER: B




Q.2 All exception classes are derived from which built-in class?

A) Exception
B) Finally
C) SystemException.
D) None of the above.

View Answer / Hide Answer

ANSWER: A




Q.3 Which of the following statements is correct about an Exception?

A) It occurs at compile time.
B) It occurs at run-time.
C) It occurs at load time.
D) None of the above.

View Answer / Hide Answer

ANSWER: B




Q.4 Trace the output of given below code.

using System;

class MyProgram
{
static void Main(string[] args)
{
int val = 100;
int[] a = new int[5];
try
{
a[6] = val;
}
catch (IndexOutOfRangeException e)
{
Console.WriteLine (“Index out of bounds”);
}
Console.WriteLine("Welcome at careerRide.");
}
}


A) Index out of bounds.
B) Welcome at careerRide.
C) Index out of bounds
Welcome at careerRide.
D) None of the above.

View Answer / Hide Answer

ANSWER: C




Q.5 Choose the correct option according to given below statement.

Statement 1: A try block must be associated with at least one catch or finally block.
Statement 2: Try block can be nested.
Statement 3: Try block cannot be nested.
Statement 4: A try block must be associated with finally block.

A) Statement 1 and 2 are correct.
B) Only statement 3 is correct.
C) Statement 3, and 4 are correct.
D) Only Statement 4 is correct.

View Answer / Hide Answer

ANSWER: A




Q.6 Which of the following statements are correct about exception handling in C#.NET?

A) A program can contain multiple finally clauses.
B) finally clause will always executed, No matter whether an exception occurs or not.
C) A program cannot contain multiple finally clauses.
D) Option B and C are correct.

View Answer / Hide Answer

ANSWER: D




Q.7 Choose the correct option according to given below statement.

Statement 1: User-defined exceptions can be created.
Statement 2: All types of exceptions can be caught using the Exception class.
Statement 3: User-defined exceptions cannot be created.

A) Statement 1 and 2 are correct.
B) Only statement 3 is correct.
C) Statement 2, and 3 are correct.
D) Only Statement 1 is correct.

View Answer / Hide Answer

ANSWER: A




Q.8 if your program does not catch an exception, then exception is catches by

A) CTS
B) CLR
C) CLS
D) None of the above.

View Answer / Hide Answer

ANSWER: B




Q.9 Trace the output of given below code.

using System;

class Program
{
static void Main(string[] args)
{
try
{
Console.WriteLine("Welcome at careerRide");
}
catch (Exception e)
{
Console.WriteLine("Exception catched");
}
catch (DivideByZeroException e)
{
Console.WriteLine(" Divide by zero exception");
}
finally
{
Console.WriteLine("finally block executed");
}
}
}

A) Compile time error
B) Welcome at careerRide
C) Exception catched
D) finally block executed

View Answer / Hide Answer

ANSWER: A




Q. 10 Trace the output of given below code.

using System;

class MyProgram
{
static void Main(string[] args)
{

try
{
Console.WriteLine("Welcome to careerRide");
}

}
}


A) Welcome to careerRide
B) Compile time error
C) Run time error.
D) None of the above.

View Answer / Hide Answer

ANSWER: B



Post your comment