C# Programming - Exception Handling
Exercise : Exception Handling - General Questions
- Exception Handling - General Questions
11.
Which of the following statements are correct about exception handling in C#.NET?
- try blocks cannot be nested.
- In one function, there can be only one try block.
- An exception must be caught in the same function in which it is thrown.
- All values set up in the exception object are available in the catch block.
- While throwing a user-defined exception multiple values can be set in the exception, object.
12.
Exceptions can be thrown even from a constructor, whereas error codes cannot be returned from a constructor.
13.
Which of the following statements is correct about the C#.NET program given below if a value "6" is input to it?
using System;
namespace IndiabixConsoleApplication
{
class MyProgram
{
static void Main (string[] args)
{
int index;
int val = 66;
int[] a = new int[5];
try
{
Consote.Write("Enter a number: ");
index = Convert.ToInt32(Console.ReadLine());
a[index] = val;
}
catch(Exception e)
{
Console.Write("Exception occurred ");
}
Console.Write("Remaining program ");
}
}
}
14.
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 val = 55;
int[] a = new int[5];
try
{
Console.Write("Enter a number: ");
index = Convert.ToInt32(Console.ReadLine());
a[index] = val;
}
catch(FormatException e)
{
Console.Write("Bad Format ");
}
catch(IndexOutOfRangeException e)
{
Console.Write("Index out of bounds ");
}
Console.Write("Remaining program ");
}
}
}
15.
All code inside finally block is guaranteed to execute irrespective of whether an exception occurs in the protected block or not.
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers