Curioustab
Aptitude
General Knowledge
Verbal Reasoning
Computer Science
Interview
Take Free Test
Aptitude
General Knowledge
Verbal Reasoning
Computer Science
Interview
Take Free Test
Exception Handling Questions
C#.NET — Object-Oriented way to handle run-time errors: choose the correct mechanism.
C#.NET — When do exceptions occur? Choose the correct phase.
C#.NET — Predict output with try/catch for invalid numeric input. Program reads an index and stores val = 55 in an array element. Input provided: "ABCD". What is printed?
C#.NET — Predict output with general exception handling and out-of-range index. Input provided: "6". What is printed?
C#.NET — What will this program print if the user types the non-numeric text "ABCD"? using System; namespace CuriousTabConsoleApplication { class MyProgram { 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"); } } }
C#.NET — What will this program print when it tries to write a[6] (array size 5)? using System; namespace CuriousTabConsoleApplication { class MyProgram { static void Main(string[] args) { int index = 6; int val = 44; int[] a = new int[5]; try { a[index] = val; } catch (IndexOutOfRangeException e) { Console.Write("Index out of bounds "); } Console.Write("Remaining program"); } } }
C#.NET — Is all code in a finally block guaranteed to run, regardless of whether an exception occurs in the associated try block?
C#.NET — Interpreting an unhandled exception report: Unhandled Exception: System.IndexOutOfRangeException: Index was outside the bounds of the array. at CuriousTabConsoleApplication.Program.Main(String[] args) in D:\ConsoleApplication\Program.cs:line 14 Which statements are correct?
C#.NET — Which of the following is NOT an exception (i.e., not a standard .NET exception condition/class)?
C#.NET — If an exception is not caught by your code, who catches it?
C#.NET — True or False: A constructor can throw exceptions, but it cannot return an error code.
C#.NET — Which of the following is NOT a valid .NET exception class?
C#.NET — What will this program print if the user enters "6" for the index? using System; namespace CuriousTabConsoleApplication { class MyProgram { static void Main(string[] args) { int index; int val = 44; 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"); } } }
C#.NET — Which statements about exception handling are correct? 1) If our program does not catch an exception then the .NET CLR catches it. 2) It is possible to create user-defined exceptions. 3) All types of exceptions can be caught using the Exception class. 4) CLRExceptions is the base class for all exception classes. 5) For every try block there must be a corresponding finally block.
C#.NET — Exception handling basics: identify the correct facts about try/catch/finally. Which statements are correct? If an exception occurs, the program always terminates abruptly with no chance to recover. Whether or not an exception occurs, the statements in the finally block (if present) will execute. A program can contain multiple finally blocks for the same try. A finally block is written after the try (and optional catch) blocks, not inside the try body. A finally block is commonly used for cleanup such as closing files, network sockets, or database connections.
C#.NET — Read a stack trace: what does this “IndexOutOfRangeException” report tell you? Unhandled Exception: System.IndexOutOfRangeException: Index was outside the bounds of the array at CuriousTabConsoleApplication.MyProgram.SetVal(Int32 index, Int32 val) in D:\Sample\CuriousTabConsoleApplication\MyProgram.cs:line 26 at CuriousTabConsoleApplication.MyProgram.Main(String[] args) in D:\Sample\CuriousTabConsoleApplication\MyProgram.cs:line 20
C#.NET — Exception handling rules: pick the true statements. try blocks cannot be nested. Only one try block is allowed per function. An exception must be caught in the same function where it is thrown. Values set in the exception object are available in the catch block. When throwing a user-defined exception, multiple data values can be stored in the exception object (for retrieval in catch).
C#.NET — True or False: Any class whose instances are thrown using throw must derive (directly or indirectly) from System.Exception.