Exercise: Exception Handling

Questions for: Exception Handling

In Python, what is the purpose of the assert statement?
A:
To handle exceptions
B:
To define custom exception classes
C:
To check if a condition is True, otherwise raise an AssertionError
D:
To terminate the program immediately
Answer: C
The assert statement is used to check if a condition is True. If the condition is False, it raises an AssertionError, allowing you to catch unexpected conditions during development.
It is compulsory for all classes whose objects can be thrown with throw statement to be derived from System.Exception class.
A:
True
B:
False
C:
D:
Answer: B
No answer description is available. Let's discuss.
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 ExamAdept
{
    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");
        }
    }
}
A:
It will output: Exception occurred
B:
It will output: Remaining program
C:
It will output: Remaining program Exception occurred
D:
It will output: Exception occurred Remaining program
Answer: D
No answer description is available. Let's discuss.
Which of the following is NOT an Exception?
A:
StackOverflow
B:
Division By Zero
C:
Insufficient Memory
D:
Incorrect Arithmetic Expression
Answer: D
No answer description is available. Let's discuss.
All code inside finally block is guaranteed to execute irrespective of whether an exception occurs in the protected block or not.
A:
True
B:
False
C:
D:
Answer: A
No answer description is available. Let's discuss.
Ad Slot (Above Pagination)
Quiz