PYTHON Exception Handling MCQs

  1. Which keyword is used to handle exceptions in Python?
    a) try
    b) catch
    c) except
    d) finally
    View Answer

    Correct answer: A — try

  2. What will be printed?
    1 try:
    2 print(10/0)
    3 except ZeroDivisionError:
    4 print("Eduinq Error")
    a) Eduinq Error
    b) ZeroDivisionError
    c) Error
    d) None
    View Answer

    Correct answer: A — Eduinq Error

  3. Which of the following is used to raise exception manually?
    a) throw
    b) raise
    c) error
    d) except
    View Answer

    Correct answer: B — raise

  4. What is the output of print(type(Exception))?
    a) <class 'type'>
    b) <class 'Exception'>
    c) Error
    d) None
    View Answer

    Correct answer: A — <class 'type'>

  5. Which of the following is used to execute code regardless of exception?
    a) finally
    b) except
    c) try
    d) raise
    View Answer

    Correct answer: A — finally

  6. What will be printed?
    1 try:
    2 x = int("Eduinq")
    3 except ValueError:
    4 print("Error")
    a) Error
    b) Eduinq
    c) None
    d) Exception
    View Answer

    Correct answer: A — Error

  7. Which of the following is base class for all exceptions?
    a) Exception
    b) BaseException
    c) Error
    d) RuntimeError
    View Answer

    Correct answer: B — BaseException

  8. What is the output of print(isinstance(ZeroDivisionError(),Exception))?
    a) True
    b) False
    c) Error
    d) None
    View Answer

    Correct answer: A — True

  9. Which of the following is used to catch multiple exceptions?
    a) except (Error1,Error2)
    b) except Error1,Error2
    c) except Error1|Error2
    d) except Error1+Error2
    View Answer

    Correct answer: A — except (Error1,Error2)

  10. What will be printed?
    1 try:
    2 print(1/0)
    3 except (ZeroDivisionError,ValueError):
    4 print("Eduinq Exception")
    a) Eduinq Exception
    b) Error
    c) None
    d) ZeroDivisionError
    View Answer

    Correct answer: A — Eduinq Exception

  11. Which of the following is used to define custom exception?
    a) class MyError(Exception)
    b) def MyError(Exception)
    c) error MyError(Exception)
    d) raise MyError(Exception)
    View Answer

    Correct answer: A — class MyError(Exception)

  12. What is the output of print(issubclass(ZeroDivisionError,Exception))?
    a) True
    b) False
    c) Error
    d) None
    View Answer

    Correct answer: A — True

  13. Which of the following is used to catch all exceptions?
    a) except Exception:
    b) except:
    c) Both A and B
    d) None
    View Answer

    Correct answer: C — Both A and B

  14. What will be printed?
    1 try:
    2 print("Eduinq")
    3 finally:
    4 print("Python")
    a) Eduinq Python
    b) Python Eduinq
    c) Error
    d) None
    View Answer

    Correct answer: A — Eduinq Python

  15. Which of the following is used to re raise exception?
    a) raise
    b) throw
    c) except
    d) error
    View Answer

    Correct answer: A — raise

  16. What is the output of print(isinstance(Exception(),BaseException))?
    a) True
    b) False
    c) Error
    d) None
    View Answer

    Correct answer: A — True

  17. Which of the following is used to catch exception object?
    a) except Exception as e
    b) except Exception e
    c) except e Exception
    d) except e
    View Answer

    Correct answer: A — except Exception as e

  18. What will be printed?
    1 try:
    2 raise ValueError("Eduinq")
    3 except ValueError as e:
    4 print(e)
    a) Eduinq
    b) ValueError
    c) Error
    d) None
    View Answer

    Correct answer: A — Eduinq

  19. Which of the following is used to catch specific exception?
    a) except ValueError:
    b) except Exception:
    c) except:
    d) raise ValueError
    View Answer

    Correct answer: A — except ValueError:

  20. What is the output of print(issubclass(ValueError,BaseException))?
    a) True
    b) False
    c) Error
    d) None
    View Answer

    Correct answer: A — True

  21. Which of the following is used to define assertion error?
    a) assert condition
    b) raise AssertionError
    c) Both A and B
    d) None
    View Answer

    Correct answer: C — Both A and B

  22. What will be printed?
    1 try:
    2 assert 2>3
    3 except AssertionError:
    4 print("Eduinq Assertion")
    a) Eduinq Assertion
    b) Error
    c) None
    d) True
    View Answer

    Correct answer: A — Eduinq Assertion

  23. Which of the following is used to catch IOError?
    a) except IOError:
    b) except OSError:
    c) Both A and B
    d) None
    View Answer

    Correct answer: C — Both A and B

  24. What is the output of print(isinstance(IOError(),OSError))?
    a) True
    b) False
    c) Error
    d) None
    View Answer

    Correct answer: A — True

  25. Which of the following is used to catch KeyboardInterrupt?
    a) except KeyboardInterrupt:
    b) except Interrupt:
    c) except KeyError:
    d) except Exception:
    View Answer

    Correct answer: A — except KeyboardInterrupt:

  26. What will be printed?
    1 try:
    2 raise KeyboardInterrupt
    3 except KeyboardInterrupt:
    4 print("Eduinq Interrupt")
    a) Eduinq Interrupt
    b) Error
    c) None
    d) KeyboardInterrupt
    View Answer

    Correct answer: A — Eduinq Interrupt

  27. Which of the following is used to catch IndexError?
    a) except IndexError:
    b) except KeyError:
    c) except ValueError:
    d) except Exception:
    View Answer

    Correct answer: A — except IndexError:

  28. What is the output of print(isinstance(IndexError(),LookupError))?
    a) True
    b) False
    c) Error
    d) None
    View Answer

    Correct answer: A — True

  29. Which of the following is used to catch KeyError?
    a) except KeyError:
    b) except IndexError:
    c) except ValueError:
    d) except Exception:
    View Answer

    Correct answer: A — except KeyError:

  30. What will be printed?
    1 try:
    2 d = {"Eduinq":1}
    3 print(d["Python"])
    4 except KeyError:
    5 print("Key Error")
    a) Key Error
    b) Eduinq
    c) Error
    d) None
    View Answer

    Correct answer: A — Key Error

  31. Which of the following is used to catch TypeError?
    a) except TypeError:
    b) except ValueError:
    c) except Exception:
    d) except Error:
    View Answer

    Correct answer: A — except TypeError:

  32. What is the output of print(isinstance(TypeError(),Exception))?
    a) True
    b) False
    c) Error
    d) None
    View Answer

    Correct answer: A — True

  33. Which of the following is used to catch AttributeError?
    a) except AttributeError:
    b) except Error:
    c) except Exception:
    d) except ValueError:
    View Answer

    Correct answer: A — except AttributeError:

  34. What will be printed?
    1 try:
    2 x = 10
    3 x.append(5)
    4 except AttributeError:
    5 print("Eduinq Attribute Error")
    a) Eduinq Attribute Error
    b) Error
    c) None
    d) AttributeError
    View Answer

    Correct answer: A — Eduinq Attribute Error

  35. Which of the following is used to catch ImportError?
    a) except ImportError:
    b) except ModuleError:
    c) except Exception:
    d) except Error:
    View Answer

    Correct answer: A — except ImportError:

  36. What is the output of print(isinstance(ImportError(),Exception))?
    a) True
    b) False
    c) Error
    d) None
    View Answer

    Correct answer: A — True

  37. Which of the following is used to catch RuntimeError?
    a) except RuntimeError:
    b) except Error:
    c) except Exception:
    d) except ValueError:
    View Answer

    Correct answer: A — except RuntimeError:

  38. What will be printed?
    1 try:
    2 raise RuntimeError("Eduinq Runtime")
    3 except RuntimeError as e:
    4 print(e)
    a) Eduinq Runtime
    b) Error
    c) None
    d) RuntimeError
    View Answer

    Correct answer: A — Eduinq Runtime

  39. Which of the following is used to catch MemoryError?
    a) except MemoryError:
    b) except Error:
    c) except Exception:
    d) except ValueError:
    View Answer

    Correct answer: A — except MemoryError:

  40. What will be printed?
    1 try:
    2 a = [1]*1000000000
    3 except MemoryError:
    4 print("Eduinq Memory Error")
    a) Eduinq Memory Error
    b) Error
    c) None
    d) MemoryError
    View Answer

    Correct answer: A — Eduinq Memory Error

  41. Which of the following is used to catch StopIteration?
    a) except StopIteration:
    b) except IterationError:
    c) except Exception:
    d) except Error:
    View Answer

    Correct answer: A — except StopIteration:

  42. What is the output of print(isinstance(StopIteration(),Exception))?
    a) True
    b) False
    c) Error
    d) None
    View Answer

    Correct answer: A — True

  43. Which of the following is used to catch EOFError?
    a) except EOFError:
    b) except EndError:
    c) except Exception:
    d) except Error:
    View Answer

    Correct answer: A — except EOFError:

  44. What will be printed?
    1 try:
    2 raise EOFError
    3 except EOFError:
    4 print("Eduinq EOF")
    a) Eduinq EOF
    b) Error
    c) None
    d) EOFError
    View Answer

    Correct answer: A — Eduinq EOF

  45. Which of the following is used to catch FloatingPointError?
    a) except FloatingPointError:
    b) except FloatError:
    c) except Exception:
    d) except Error:
    View Answer

    Correct answer: A — except FloatingPointError:

  46. What is the output of print(isinstance(FloatingPointError(),ArithmeticError))?
    a) True
    b) False
    c) Error
    d) None
    View Answer

    Correct answer: A — True

  47. Which of the following is used to catch OverflowError?
    a) except OverflowError:
    b) except Error:
    c) except Exception:
    d) except ValueError:
    View Answer

    Correct answer: A — except OverflowError:

  48. What will be printed?
    1 try:
    2 import math
    3 print(math.exp(1000))
    4 except OverflowError:
    5 print("Eduinq Overflow")
    a) Eduinq Overflow
    b) Error
    c) None
    d) OverflowError
    View Answer

    Correct answer: A — Eduinq Overflow

  49. Which of the following is used to catch ZeroDivisionError?
    a) except ZeroDivisionError:
    b) except DivisionError:
    c) except Exception:
    d) except Error:
    View Answer

    Correct answer: A — except ZeroDivisionError:

  50. What will be printed?
    1 try:
    2 print(1/0)
    3 except ZeroDivisionError:
    4 print("Eduinq Division Error")
    a) Eduinq Division Error
    b) Error
    c) None
    d) ZeroDivisionError
    View Answer

    Correct answer: A — Eduinq Division Error

Quick Links to Explore