Back to Topic 6.1 — Programming fundamentals
6.1.3Computer Science SL5 flashcards

Exception handling

Practice Flashcards

Flip to reveal answers
Card 1 of 56.1.3
6.1.3
Question

What is an exception?

Click to reveal answer

Track your progress — Sign up free to save your progress and get smart review reminders based on spaced repetition.

All 5 Flashcards — Exception handling

Sign up free to track progress and get spaced-repetition review schedules.

Card 1definition

Question

What is an exception?

Answer

A problem that appears while the program is running, rather than a mistake in the code's grammar. Without handling the program simply stops; with handling it can report the problem and carry on.

Card 2definition

Question

What do try, except and finally each do?

Answer

try holds only the lines that might fail. except (catch in Java) handles one specific kind of failure. finally runs whether or not anything failed, and is where files get closed.

Card 3definition

Question

What are the three sources of failure to look for?

Answer

Unexpected input, usually from people; unavailable resources such as a missing file or unresponsive network; and logic errors, where the code ran on values nobody planned for.

Card 4concept

Question

When should you validate rather than catch?

Answer

When the problem is predictable and inside your control — an empty list, a zero divisor. Catch the things outside it: files, networks and databases, which can fail between your check and your use.

Card 5concept

Question

Why must closing a file go in finally?

Answer

If a line inside try fails, control jumps straight to except and any later lines in try never run. finally runs either way, so the file is closed rather than left open holding a system resource.

Track your progress with spaced repetition

Sign up free — Aimnova tells you exactly which cards to review and when, so you remember everything before your IB exam.

Start Free
IB Computer Science Exception handling Flashcards | 6.1.3 | Aimnova