In C#, what happens if an exception occurs inside a catch block?
A. The exception is caught and handled by the same block
B. The program terminates
C. The exception propagates to the calling method
D. The catch block is skipped
Select an option to see the answer and solution.
Which of the following is NOT a standard exception class provided by .NET Framework in C#?
A. InvalidOperationException
B. DivideByZeroException
C. ArgumentNullException
D. SQLException
Select an option to see the answer and solution.
In C#, which keyword is used to specify that a method can throw a particular type of exception?
A. throws
B. catch
C. exception
D. throw
Select an option to see the answer and solution.
What is the process of converting a custom exception object into a standard exception object in C# called?
A. Demarshalling
B. Marshalling
C. Wrapping
D. Unwrapping
Select an option to see the answer and solution.
In C#, what happens if no catch block matches the exception type thrown in a try block?
A. The program terminates
B. The finally block is executed
C. The finally block is skipped
D. The exception is propagated to the calling method
Select an option to see the answer and solution.
What is the purpose of the try block in exception handling in C#?
A. To clean up resources
B. To execute code that must always run
C. To enclose the code that might throw an exception
D. To catch an exception
Select an option to see the answer and solution.
In C#, which block is used to handle exceptions that may occur within a try block?
A. try
B. finally
C. throw
D. catch
Select an option to see the answer and solution.
What is the purpose of the finally block in C# exception handling?
A. To execute cleanup code regardless of whether an exception occurs or not
B. To handle specific types of exceptions
C. To define custom exceptions
D. To propagate exceptions
Select an option to see the answer and solution.
Which statement is used to throw an exception in C#?
A. finally
B. try
C. catch
D. throw
Select an option to see the answer and solution.
In C#, which of the following keywords is used to define a custom exception class?
A. exception
B. custom
C. class
D. throw
Select an option to see the answer and solution.
What is the term for an exception that occurs during the execution of a program in C#?
A. Syntax Error
B. Runtime Exception
C. Logic Error
D. None of the above
Select an option to see the answer and solution.
In C#, what is the purpose of the using statement in exception handling?
A. To declare exception types
B. To define custom exceptions
C. To ensure resources are properly disposed
D. To handle exceptions
Select an option to see the answer and solution.
Which keyword is used to specify a block of code where an exception might occur in C#?
A. catch
B. finally
C. throw
D. try
Select an option to see the answer and solution.
In C#, which class is the base class for all exceptions?
A. Exception
B. Error
C. Throwable
D. ThrowableException
Select an option to see the answer and solution.
What is the purpose of the catch block in C# exception handling?
A. To clean up resources in case of an exception
B. To define custom exceptions
C. To throw the exception
D. To handle and process the exception
Select an option to see the answer and solution.
What is the term for handling an exception and continuing program execution in C#?
A. Exception Throwing
B. Exception Ignoring
C. Exception Handling
D. Exception Resuming
Select an option to see the answer and solution.
In C#, what happens if an exception is thrown inside a finally block?
A. The exception is caught and handled by the finally block
B. The exception replaces any previously thrown exception
C. The finally block is skipped
D. None of the above
Select an option to see the answer and solution.
What is the purpose of the try-catch block in C#?
A. To handle exceptions that may occur in a block of code
B. To throw exceptions
C. To declare custom exceptions
D. To clean up resources in case of an exception
Select an option to see the answer and solution.
Which statement is used to specify code that should always run regardless of whether an exception occurs in C#?
A. throw
B. try
C. catch
D. finally
Select an option to see the answer and solution.
What will be the output of the following C# code?
class student
{
int []scores = new int[3] {13, 32, 24};
public int this[int index]
{
get
{
if (index < 3)
return scores[index];
else
{
Console.WriteLine("invalid index");
return 0;
}
}
private set
{
if (index < 3)
scores[index] = value;
else
Console.WriteLine("invalid index");
}
}
}
class Program
{
public static void Main(string[] args)
{
student s = new student();
int[] scores1 = new int[3] {8, 19, 40};
for (int i = 0; i < 3; i++)
{
if (scores1[i] > s[i])
{
Console.WriteLine(" scores1 had greater value :" + scores1[i]);
}
else
{
Console.WriteLine("scores had greater value :" + s[i]);
}
}
Console.ReadLine();
}
}A. 0
B. Compile time error
C. Run time error
D. scores had greater value : 13
scores had greater value : 32
scores1 had greater value : 40
Select an option to see the answer and solution.