Menu

Try and Throw

Card 1 of 17 0 got it 0 still learning
Question
TapClick or press space to see the answer
Answer
All 17 cards in this set
Which term describes a run-time error that can be caught instead of stopping the program?
Exception
What is meant by 'try' in Python?
A block of code that is run and may cause an error
In Python, which keyword is used to signal that an error has occurred?
Raise
What is meant by 'throw' in languages such as Java and JavaScript?
To signal that an exception has occurred
Which term describes the action of dealing with an exception so that the program does not crash?
Catch
In Python, which keyword starts the block of code that runs when an error is caught?
Except
A program asks for an age, the user enters -5, and the program stores it and prints a result. What does this show?
Invalid input was used and the program gave a wrong result
A program runs int(input()) to read a whole number and the user types the word hello. What happens in Python?
The program stops with a ValueError
What is the purpose of a try and except block in Python?
To catch a run-time error so the program does not crash
When an error happens inside a try block, what happens to the statements in that block that have not yet run?
They are skipped and the except block runs instead
In Python, what does except ValueError catch?
Only errors from text that is not a whole number
A programmer catches ValueError around int(input()) but adds no range check. The user enters 500 as an age. What happens?
500 is accepted because it is a whole number
What is the usual way for a program to deal with invalid input from a user?
Check the input before using it and ask again until it is valid
A try and except block sits inside a loop that repeats until the input is a whole number. The user enters ten, then 15. What happens?
A message appears once, then the age 15 is accepted
A while loop keeps asking for an age until valid is True. Why does the line valid = True run after the input has been converted?
So the loop stops once the input has converted
The code inside a try block runs without any error. What happens to the except block below it?
It is skipped and the program carries on
A program uses a while loop with a range check to accept an age between 0 and 120. The user enters 150, then -3, then 15. What is shown?
The message twice, then the age is accepted