C# Programming - Exception Handling - Discussion

Discussion Forum : Exception Handling - General Questions (Q.No. 17)
17.
Which of the following statements is correct about the C#.NET program given below if a value "ABCD" is input to it?
using System;
namespace IndiabixConsoleApplication
{
    class MyProgram
    {
        static void Main(string[] args)
        {
            int index; 
            int vat = 88;
            int[] a = new int(5];
            try
            {
                Console.Write("Enter a number: ");
                index = Convert.Toint32(Console.ReadLine());
                a[index] = val;
            }
            catch(Exception e)
            {
                Console.Write("Exception occurred");
            }
            Console.Write("Remaining program");
        }
    }
}
It will output: Exception occurred
It will output: Remaining program
It will output: Remaining program Exception occurred
It will output: Exception occurred Remaining program
The value 88 will get assigned to a[0].
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
3 comments Page 1 of 1.

Kevin said:   7 years ago
@All.

The Code should read: ( int val = 88 not "int vat = 88" and int[] a = new int[5] not "int[] a = new int(5];").

static void Main(string[] args)
{
int index;
int val = 88;
int[] a = new int[5];
try
{
Console.Write("Enter a number: ");
index = Convert.ToInt32(Console.ReadLine());
a[index] = val;
}
catch (Exception e)
{
Console.Write("Exception occurred");
}
Console.Write("Remaining program");

}

Shraddha said:   1 decade ago
The answer should be Remaining program. Because exception is not there in the codes. ABCD is a character and converted into integer, so program will run correctly without any error or exception.

Tyrone Atkins said:   9 years ago
Line 9, an error in the code for val. 'vat' is shown as opposed to val.

Post your comments here:

Your comments will be displayed after verification.