What will be the output of the following C# code snippet?
class Program
{
static void Main(string[] args)
{
int i;
int v = 40;
int[] x = new int[5];
try
{
Console.WriteLine(" Enter the number: ");
index = Convert.ToInt32(Console.ReadLine());
x[index] = v;
}
catch(Exception e)
{
Console.WriteLine("Exception occurred");
}
Console.WriteLine("Program executed");
}
}
class Program
{
static void Main(string[] args)
{
int i;
int v = 40;
int[] x = new int[5];
try
{
Console.WriteLine(" Enter the number: ");
index = Convert.ToInt32(Console.ReadLine());
x[index] = v;
}
catch(Exception e)
{
Console.WriteLine("Exception occurred");
}
Console.WriteLine("Program executed");
}
}A. Exception occurred
B. Program executed
C. Exception occurred
Program executed
D. Program executed
Exception occurred
Answer: Option C
Related Questions on Exception Handling in C Sharp
What is the purpose of exception handling in C#?
A. To enhance program performance
B. To avoid writing error messages
C. To gracefully handle runtime errors
D. To simplify debugging
What is the default exception handler in C# called?
A. Standard Exception Handler
B. Unhandled Exception Handler
C. Global Exception Handler
D. None of the above
A. throw
B. catch
C. finally
D. try

Join The Discussion