Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Introduction To Programming - Lesson Exception Handling

Total questions: 13

Worksheet time: 7mins

Name
Class
Date
1.

Why Use Error Handling? Error handling ensures that your program can handle unexpected situations without crashing, helping improve user experience and program stability.

a)

To improve user experience and program stability

b)

To make the program run slower

c)

To increase the complexity of the code

d)

To reduce the need for testing

2.

Error Handling is:

a)

a process of responding to the occurrence of exceptions during computation

b)

a method to increase the speed of a program

c)

a technique to optimize memory usage

d)

a way to enhance the user interface

3.

What are Exceptions?

a)

A type of error handling mechanism

b)

A type of loop

c)

A type of variable

d)

A type of function

4.

Throwing Exceptions: When a program encounters an error condition, it "throws" an exception. This is like the program signaling that something went wrong and needs to be addressed.

a)

True

b)

False

5.

Catching Exceptions: When an exception is thrown, it can be "caught" by the program. This prevents the program from crashing and allows you to handle the error in a controlled way. In Python, this is done using the try and except blocks.

a)

True

b)

False

6.

Finally Block: The finally block is a piece of code that runs after the try-except block, no matter whether an exception was thrown or caught. It is typically used for cleanup operations (like closing files or freeing resources).

a)

True

b)

False

7.

What is the purpose of the Try Block in Python?

a)

To handle exceptions

b)

To write code that might raise an exception

c)

To execute cleanup code

8.

What does the Except Block do in Python?

a)

It runs code that should execute no matter what

b)

It is used to catch and handle specific exceptions

c)

It writes code that might raise an exception

9.

The purpose of the Finally Block in Python is to:

a)

Execute code regardless of whether an exception is raised or not.

b)

Handle exceptions that are not caught by except blocks.

c)

Terminate the program immediately when an exception occurs.

d)

Log error messages to a file.

10.

The suspicious code is put inside the

a)

Try Block

b)

Finally Block

c)

Else Block

d)

Except Block

11.

The unexpected event happened during program execution should be handled by

a)

EXCEPTION

b)

EXPERIMENT

c)

ASSERTION

d)

EXTRAORDINARY

12.

Exception disrupts the

a)

Normal flow of the program

b)

Abnornal flow of the program

c)

Hard Disk

d)

None of the Above

13.

What happens if an exception is thrown in a function, but not caught?

a)

The program continues executing and it is ignored.

b)

The function that throws the exception is exited.

c)

The program terminates.

d)

The compiler will find the error and the program would not compile.