wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

CompuScholar Chapter 11

Total questions: 20

Worksheet time: 10mins

Name
Class
Date
1.

Which of the following is NOT an example of a run-time error?

a)

You forgot to add a semicolon to the end of a statement

b)

Your program throws an exception

c)

Your player sprite moves left when you hit the right arrow key

d)

These are all examples of run-time errors

2.

If an exception is thrown at run-time, what happens to the lines of code immediately after the line where the exception was thrown?

a)

Those lines are not executed

b)

Those lines are executed normally

c)

Those lines are executed in the debugger

d)

Those lines will execute only if they also don't throw exceptions

3.

Which of the following exceptions is most likely to happen if you try to use a reference variable that has not been initialized with a valid object?

a)

NullReferenceException

b)

DivideByZeroException

c)

InvalidCastException

d)

CrazyLogicException

4.

What is the purpose of using try and catch keywords to mark blocks of code?

a)

To identify blocks that may throw exceptions and to cleanly handle exceptions if they are thrown

b)

To advertise to the user that the program may not work correctly

c)

To identify and process experimental code that extends beyond the C# language

d)

To re-run risky code over and over again until the correct result is produced

5.

What happens by default if a Unity script throws an exception?

a)

The Unity engine will catch it and display the exception message to the console

b)

The game will crash immediately

c)

The game will run more slowly

d)

The user is prompted to request a refund

6.

.How can you get Unity to tell you exactly where an exception was thrown?

a)

Double-click on the red exception message in the Console

b)

Select Debug, then Exceptions, then Locate from the menu

c)

Right-click on the red exception message and select "Properties"

d)

View the exception in the Inspector panel

7.

When an exception is thrown, what two useful pieces of information are you given?

a)

A description of the exception and the specific line of code that threw the exception

b)

A description of the exception and a recommendation for how to fix it

c)

The number of times the exception has happened and the resulting impact on your program

d)

The specific line of code that caused the problem and a specific fix for that line of code

8.

Which of the following is NOT a recommended approach for finding and fixing run-time behavioral problems in your code?

a)

Run the program repeatedly until you can guess the solution

b)

Conduct a code review

c)

Add program trace statements to help understand the flow

d)

Use a debugger to study your program as it runs

9.

Which of the following steps should be part of a code review?

a)

All of these are true

b)

Review your variables and make sure they are initialized

c)

Review each function to understand when and how it is called

d)

Within a function, make sure each line of code is clear, has all the data needed to work correctly, and uses the correct logical expressions

10.

Using a code review, what is the problem with the following code?

float price = 5.0F;

if (price > 10.0F)

{ Debug.Log("I can afford that") }

else { Debug.Log("That's too expensive"); }

a)

The logical expression doesn't match the intent of the rest of the program logic

b)

The Debug.Log() statements will both execute

c)

A compile-time error will prevent it from building and running

d)

There are no problems with this code

11.

Using a code review, what is the problem with the following code?

GameObject myObject;

Debug.Log("My name is " + myObject.name);

a)

An exception will be thrown on the second statement

b)

An exception will be thrown on the first statement

c)

The Debug.Log() statement may print random information

d)

Nothing, this code will work fine

12.

Given the following code:

Debug.Log ("Here we go");

mystery1 ();

Debug.Log ("Step 1");

mystery2 ();

Debug.Log ("Step 2");

When run, if the Console contains just "Here we go" and "Step 1", what can confidently be said about the code?

a)

The mystery2() function did not complete successfully

b)

The mystery1() function did not complete successfully

c)

Neither mystery1() nor mystery2() completed successfully

d)

Both mystery1() and mystery2() completed successfully

13.

Given the following code:

Debug.Log ("Here we go");

mystery1 ();

Debug.Log ("Step 1");

mystery2 ();

Debug.Log ("Step 2");

When run, if the Console does not contain any output, what can confidently be said about the code?

a)

This block of code was not executed at all

b)

The mystery1() function started but did not complete successfully

c)

Both mystery1() and mystery2() threw an exception

d)

The mystery1() function completed but the mystery2() function did not

14.

You are concerned that a script is not correctly calling the sold() function for an item that should be priced under $10. So you add some program tracing to help you find the error.

string size = "large";

Debug.Log ("Calculating price for " + size + " item");

float price = calculatePrice(size);

Debug.Log ("Calculated price: " + price); if (price < 10.0F) { sold(); }

Which of the following things will the above tracing statements NOT help you verify?

a)

You can't tell if the logical expression in the if() statement is correct

b)

You can't tell if the input data to the calculatePrice() function is correct

c)

You can't tell if the calculatePrice() function completed and returned a valid price

d)

You can't tell any of these things from the tracing statements that were added

15.

Where do you enable the Unity debugger that will let you watch a running program line-by-line?

a)

From the Visual Studio toolbar or menu

b)

From the Unity IDE menu

c)

The debugger is a standalone program you run by double-clicking on it

d)

All of these will work

16.

Which of the following things must be done before you can use a debugger to study your program?

a)

Enable the debugger

b)

Manually run the game from the Unity IDE

c)

Both of these things must be done

d)

Neither of these things must be done

17.

How do you add or remove a breakpoint to a line of code?

a)

Click in the gray column to the left of the line or use the "Run" menu

b)

Add or remove the "breakpoint" keyword in front of a line of code

c)

Attach a breakpoint component to the script in the Unity IDE Inspector

d)

Breakpoints are set automatically when exceptions are thrown; you can't configure them yourself

18.

Given the following code...

mystery1();

mystery2();

mystery3();

...if the program is "in break" state and the mystery2() line is highlighted in yellow, which statement will execute next?

a)

mystery2();

b)

mystery1();

c)

mystery3();

d)

It is impossible to tell

19.

Which of the following debugger commands will let you enter a function and examine the individual lines within the function?

a)

Step Into

b)

Step Over

c)

Step Out

d)

Continue

20.

.How can you examine current variable contents when a program is in break state in the debugger?

a)

Look at the Locals tab

b)

Hover the mouse over the variable name to get a temporary pop-up

c)

Pin a variable pop-up to the screen so it will stay visible

d)

All of these will work