๐Ÿ”ฅ 75% OFF Early-bird โ‚น2,999 one time โณ BOARDS ARE CLOSE Lock this price before it goes up. Grab my seat โ†’
Subjects โ€บ Computer Science โ€บ Exception Handling

Exception Handling

๐Ÿ”’ Priority & marks: full access ยท 7 questions shown
๐Ÿ“Œ How to approach this chapter

In a typical paper this chapter carries about 1.1 marks. Small chapter - 1 mark MCQs and one 2-mark question some years.

  • Syntax errors are found before the program runs; exceptions (run-time errors) happen while running and can be handled.
  • try: ... except SomeError: ... else: (runs only if no exception) ... finally: (always runs). A bare except catches everything.
  • Common exceptions: ZeroDivisionError, ValueError (int("abc")), TypeError ("5"+3), IndexError, KeyError, NameError, FileNotFoundError, EOFError (end of a pickle file).
  • raise lets you throw an exception yourself. Typical 2-mark question: what is the purpose of the finally block, or write code that keeps asking for a number until a valid one is entered.
You can try the first few questions here. Start free for 5 days to open everything.