350-401 · Question #83
Which statements are used for error handling in Python?
The correct answer is B. try/except. Python Error Handling Explanation Python uses try/except blocks to handle errors and exceptions, making option B correct. When code in the try block raises an error, execution jumps to the except block, allowing you to handle the error gracefully rather than crashing the program.
Question
Which statements are used for error handling in Python?
Options
- Atry/catch
- Btry/except
- Cblock/rescue
- Dcatch/release
How the community answered
(31 responses)- A3% (1)
- B87% (27)
- C3% (1)
- D6% (2)
Explanation
Python Error Handling Explanation
Python uses try/except blocks to handle errors and exceptions, making option B correct. When code in the try block raises an error, execution jumps to the except block, allowing you to handle the error gracefully rather than crashing the program.
Options A (try/catch) and D (catch/release) are incorrect because Python does not use the keyword catch - that syntax belongs to languages like Java, JavaScript, and C++. Option C (block/rescue) is entirely invalid Python syntax; rescue is actually used in Ruby, not Python.
Memory Tip: Think "Python is EXCEPTional" - Python uses
exceptinstead ofcatch. If you seecatchin an answer about Python error handling, eliminate it immediately!
Topics
Community Discussion
No community discussion yet for this question.