ExamHoot

Predict the output when Prasath runs this code that catches multiple exception types?

try:
    value = int("abc")
except ValueError:
    print("ValueError caught")
except TypeError:
    print("TypeError caught")
finally:
    print("Cleanup done")
  1. ValueError caught\nCleanup done

  2. TypeError caught\nCleanup done

  3. ValueError caught\nTypeError caught\nCleanup done

  4. Cleanup done

Show answer & explanation

Correct answer

ValueError caught\nCleanup done

Explanation

The int("abc") raises a ValueError because "abc" cannot be converted to an integer. The ValueError except block catches it, and finally always executes.

Written by ExamHoot EditorialPublished · Updated

All 45 Exception Handling: try, except, finally questions

  1. 1.What is the primary purpose of the try-except block in Python exception handling?
  2. 2.What does the finally block do in exception handling?
  3. 3.What type of exception is raised when you divide a number by zero in Python?
  4. 4.What will happen if you don't provide an except clause after a try block?
  5. 5.Which exception is raised when you try to access an index that doesn't exist in a list?
  6. 6.What is the difference between except Exception and except BaseException in Python?
  7. 7.What exception is raised when you try to convert an incompatible string to an integer?
  8. 8.Can you have multiple except blocks for a single try block in Python?
  9. 9.What exception is raised when you try to access a dictionary key that doesn't exist?
  10. 10.What does the raise statement do in Python exception handling?
  11. 11.What exception is raised when you call a method that doesn't exist on an object?
  12. 12.What is the order of execution in a try-except-finally block?
  13. 13.What exception is raised when you use an undefined variable in your code?
  14. 14.Can you have a try block without an except block if you have a finally block?
  15. 15.What exception is raised when you perform an operation with incompatible data types?
  16. 16.Predict the output of this code snippet and identify what exception handling concept is demonstrated?
  17. 17.What will be the output when Hari runs this code that handles multiple exceptions?
  18. 18.What is the bug in Prasath's code and how should exception handling be corrected?
  19. 19.What will Arun observe when executing this code with nested try-except blocks?
  20. 20.What is the issue with Deepak's exception handling and what will be the output?
  21. 21.What is the primary purpose of the try-except block in Python exception handling?
  22. 22.What will be the output of the following code snippet when Hari executes it?
  23. 23.What is the difference between the except block and the finally block in exception handling?
  24. 24.Predict the output when Prasath runs this code that catches multiple exception types?
  25. 25.What happens when an exception is raised in the finally block during exception handling?
  26. 26.What will be the output when Ananya executes this code with nested try-except blocks?
  27. 27.What does the 'as' keyword do in an except clause when handling exceptions?
  28. 28.What will be printed when Rohan executes this code that uses the 'as' keyword?
  29. 29.What is the correct order of execution in a try-except-finally block?
  30. 30.What will be the output when Deepak runs this code that has a bare except clause?
  31. 31.What will be the output when Vikram executes this code with return statements in try-except-finally blocks?
  32. 32.What will be the output when Neha debugs this code that modifies variables in exception handling?
  33. 33.What will Arjun observe when executing this code that has exception handling with list operations?
  34. 34.What will be the output when Kavya executes this code with finally block modifying return value behavior?
  35. 35.What will Suresh see when running this code that catches a parent exception class?
  36. 36.What will be the output when Ishita executes this code with multiple return paths in exception handling?
  37. 37.What will Rajesh observe when executing this code that has a finally block that raises an exception?
  38. 38.What will be the output when Meera debugs this code that uses else clause with try-except?
  39. 39.What will Aditya observe when executing this code with exception handling in a loop?
  40. 40.What will be the output when Pooja executes this code that chains exception handling with custom logic?
  41. 41.What is the fundamental purpose of using the try-except-finally block in Python exception handling?
  42. 42.Predict the output:
  43. 43.What is the key difference between catching a specific exception type versus catching the generic Exception class in Python?
  44. 44.Predict what value will be printed:
  45. 45.Debug this code: