Exception Handling Python MCQ

Get latest and Best Python Exception Handling MCQ with answers for those preparing for Computer Science, Information Technology, Informatics Practices, Python Programming, CUET etc. compiled by well experienced and qualified IT experts.

  1. ______ is a type of errors produce in python programs

    a. Compile time error
    b. Run time error
    c. Both (a) and (b)
    d. None of these

Show Answer

c. Both (a) and (b)

  1. On encountering a _________ error, the interpreter does not execute the program unless we rectify errors, save and rerun the programs.

    a. Syntax error
    b. Logical error
    c. Runtime error
    d. All of the above

Show Answer

a. Syntax error

  1. Look at the following code and select the correct description of error shown while executing it:

    X = int(input(“Enter a Number”))
    R = X*X
    print “Square =”,R

    a. can only concatenate str (not “int”) to str
    b. missing parenthesis in call to ‘print’
    c. name ‘Print’ is not defined
    d. none of the above

Show Answer

b. missing parenthesis in call to ‘print’

  1. ________ is a python object that represents an error.

    a. Interpreter
    b. Compiler
    c. Exception
    d. Module

Show Answer

c. Exception

  1. (i)  generally all exceptions are generated when a program is syntactically correct
    (ii) SyntaxError is not considered as exception.

    a. (i) True, (ii) False
    b. (i) False, (ii) True
    c. Both are True
    d. Both are False

Show Answer

a. (i) True, (ii) False

  1. When an error occurs during the execution of a program, an exception is said to have been _____

    a. Created
    b. Asserted
    c. Triggered
    d. Raised

Show Answer

d. Raised

  1. Which of the following is not a built in exception in python?

    a. SyntaxError
    b. ValueError
    c. ZeroDivisionError
    d. ExportError

Show Answer

d. ExportError

  1. It is raised when the file specified in a program statement cannot be opened.

    a. NameError
    b. IOError
    c. ImportError
    d. EOFError

Show Answer

b. IOError

  1. It is raised when local or global variable is not defined

    a. NameError
    b. ValueError
    c. TypeError
    d. ZeroDivisionError

Show Answer

a. NameError

  1. It is raised when the denominator in a division is not found

    a. IOError
    b. ValueError
    c. TypeError
    d. ZeroDivisionError

Show Answer

d. ZeroDivisionError

  1. When you accept string instead of integer value,____ is raised.

    a. TypeError
    b. ValueError
    c. NameError
    d. SyntaxError

Show Answer

b. ValueError

  1. It is raised when user accidently hits the Delete or Esc key while executing a program

    a. TypeError
    b. ValueError
    c. KeyboardInterrupt
    d. IOError

Show Answer

c. KeyboardInterrupt

  1. It is raised when requested module definition is not found

    a. NameError
    b.ImportError
    c. TypeError
    d. IndentationError

Show Answer

b.ImportError

  1. It is raised due to incorrect indentation in the program

    a. IndentationError
    b. IOError
    c. SyntaxError
    d. TypeError

Show Answer

a. IndentationError

  1. It is raised when the result of a calculation exceeds the maximum limit for numeric data type

    a. ZeroDivisionError
    b. OverFlowError
    c. TypeError
    d. ValueError

Show Answer

b. OverFlowError

  1. The process of creating exception object and handing it over to runtime system is called

    a. Catching Exception
    b. Throwing Exception
    c. Raising Exception
    d. Asserting Exception

Show Answer

b. Throwing Exception

  1. Searching and executing appropriate exception handler that can handle the raised exception

    a. Catching exception
    b. Throwing exception
    c. Handling exception
    d.  Asserting exception

Show Answer

a. Catching exception

  1. An exception is said to be caught when

    a. Error encountered and exception object is created
    b. Runtime system searches for appropriate exception handler
    c. Code that is designed to handle exception is executed
    d. None of these

Show Answer

c. Code that is designed to handle exception is executed

  1. Which of the following describes the exception handling process correctly?

    a. Exception raised -> searches for exception handler -> create exception object -> execute code of exception handler
    b. Exception raised -> create exception object -> searches for exception handler -> execute code of exception handler
    c. Create exception object -> exception raised -> searcher for exception handler -> execute code of exception handler
    d. Create exception object -> searches for exception handler -> exception raised -> execute code of exception handler

Show Answer

c. Create exception object -> exception raised -> searcher for exception handler -> execute code of exception handler

  1. Exceptions are caught in

    a. Try block
    b. Except block
    c. Finally block
    d. Else block

Show Answer

a. Try block

  1. Exceptions are handled in

    a. Try block
    b. Except block
    c. Finally block
    d. Else block

Show Answer

b. Except block

  1. The statement written inside _____ block is always executed regardless of whether an exception has occurred or not

    a. Try
    b. Except
    c. Else
    d. Finally

Show Answer

d. Finally

  1. Which of the following statement is not true about try..except block?

    a. Every try block must be followed by at least an except block
    b. A try block can be followed by more than one except block
    c. The statement inside the except block is always executed regardless of whether exception has occurred in try block or not
    d. An except clause can be added without specifying any exception

Show Answer

c. The statement inside the except block is always executed regardless of whether exception has occurred in try block or not

  1. Which of the following is not true?

    (i) The statement inside else block is executed regardless of whether there except block is executed or not.
    (ii) If an exception is encountered, further execution of the code inside the try block is stopped and control is transferred to except block

    a. (i) True, (ii) False
    b. (i) False, (ii) True
    c. Both (i) and (ii) are True
    d. Both (i) and (ii) are False

Show Answer

b. (i) False, (ii) True

  1. Which of the following is not true?

    a. Code that might cause exception is put inside try block
    b. An except block is executed only if some exception is raised in the try block
    c. Finally block can be placed anywhere after end of try clause, such as before or after all except and else block
    d. If an exception is encountered, further execution of the code inside the try block is stopped and control is transferred to except block

Show Answer

c. Finally block can be placed anywhere after end of try clause, such as before or after all except and else block

  1. The ______ is an exception handler

    a. Try
    b. Except
    c. Finally
    d. Else

Show Answer

b. Except

  1. The keyword used with exception handling are

    a. Raise, assert, throw, catch
    b. Try, except, throw, catch
    c. Try, except, else, finally
    d. Throw, catch, finally, assert

Show Answer

c. Try, except, else, finally

  1. Which of the following keyword is not part of exception handling?

    a. Try
    b. Catch
    c. Except
    d. Finally

Show Answer

b. Catch

  1. If the exception is not handled by any of the except clauses, then it is re-raised after the execution of the finally block.

    a. True
    b. False
    c. Cant say
    d. None of these

Show Answer

a. True

  1. Advantage(s) of using exception handling in python is/are:

    a. It maintains normal flow of program
    b. It avoid the program getting crashed
    c. Separate main logic of the program from error detection and correction code
    d. All of above

Show Answer

d. All of above

  1. Advantage(s) of using exception handling in python is/are:

    a. Ensures that program does not terminate abnormally due to any error
    b. Provide standardize solutions for commonly occurring errors (exceptions)
    c. Both (a) and (b)
    d. Only (a)
    e. None of these

Show Answer

c. Both (a) and (b)

  1. What will happen If finally and except blocks are not positioned properly

    a. Program will execute, but will not display anything
    b. Program will throw exception when executed
    c. Program will not be compiled
    d. Program will execute successfully

Show Answer

c. Program will not be compiled

  1. Each try block must always be followed by at least one block that is either except or a finally block.

    a. True
    b. False
    c. May be
    d. None of these

Show Answer

a. True

  1. The ______ block is generally used to while working with files, clean up memory resources

    a. Try
    b. Except
    c. Finally
    d. Else

Show Answer

c. Finally

  1. Consider the given code and fill in the blanks:

    try:
    X = int(input(“enter a number”))
    except ___________:
        print(“please enter only numbers”)
    else:
       print(“Squeare =”,X*X)

    a. IOException
    b. ValueError
    c. ZeroDivisionError
    d. TypeError

Show Answer

b. ValueError

  1. Consider the given code and fill in the blank space with appropriate exception object name.

    try:
    X = int(input(“enter a number”))
    R = X*Y
    except ___________ :
        Print(“Please check Y is not defined”)
    else:
        Print(“Result =”,R)

    a. TypeError
    b. NameError
    c. IOerror
    d. IndexError

Show Answer

b. NameError

  1. Identify the type of exception will be thrown by given code:

    L=[12,32,40]
    print(L[4])

    a. IndexError
    b. ZeroDivisionError
    c. IOError
    d. TypeError

Show Answer

a. IndexError

  1. Look at the given code and fill in the blank space

    try:
    num1 = 10
    num2 = 0
    q = num1/num2
    except ___________:
       print(“Division is not possible as num2 is set to 0”)
    ____________:
    print(“quotient = “,q)

    a. ZeroDivisionError, finally
    b. ZeroDivisionError, else
    c. ValueError, finally
    d. ValueError, else

Show Answer

b. ZeroDivisionError, else

  1. Rajesh has written following line of code to import python pandas library but he is getting error while executing. Help him in handling and correcting given code.

    Import panda as pd
    S = pd.Series[12,23,34]

    a.
    try:
        import panda as pd
        S = pd.Series[12,23,34]
    except NameError:
       print(“Please check the name of module you are importing”)

    b.
    try:
        import panda as pd
        S = pd.Series[12,23,34]
    except ImportError:
       print(“Please check the name of module you are importing”)

    c.
    try:
        import panda as pd
        S = pd.Series[12,23,34]
    except IOError:
       print(“Please check the name of module you are importing”)

    d.
    try:
        import panda as pd
        S = pd.Series[12,23,34]
    except SyntaxError:
       print(“Please check the name of module you are importing”)

Show Answer

b. 
try:
    import panda as pd
    S = pd.Series[12,23,34]
except ImportError:
    print(“Please check the name of module you are importing”)

  1. Consider the following code and select the type of error it will generate.

    print(“exception handling program”)
    try:
    int x = 10
    if x%2 == 0:
    print(“even no”)
    else:
             print(“odd no”)

    a. SyntaxError
    b. Runtime error
    c. Logical Error
    d. No Error will be generated

Show Answer

a. SyntaxError

4 thoughts on “Exception Handling Python MCQ”

  1. Krishna Kumar Gupta

    Thank you, for providing such a great MCQs & MOCKs and Lectures to learn practice before exam’s.

  2. Sir I will try my best to score 100 percentile and will definitely message you if I did
    Tomorrow is my exam and i have prepared my best
    All because of you and Swati chawla ma’am

Leave a Comment

Your email address will not be published. Required fields are marked *

error: Content is protected !!