NEW
Font size
WorksheetsCompuScholar Chapter 11
Total questions: 20
Worksheet time: 10mins
Which of the following is NOT an example of a run-time error?
You forgot to add a semicolon to the end of a statement
Your program throws an exception
Your player sprite moves left when you hit the right arrow key
These are all examples of run-time errors
If an exception is thrown at run-time, what happens to the lines of code immediately after the line where the exception was thrown?
Those lines are not executed
Those lines are executed normally
Those lines are executed in the debugger
Those lines will execute only if they also don't throw exceptions
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?
NullReferenceException
DivideByZeroException
InvalidCastException
CrazyLogicException
What is the purpose of using try and catch keywords to mark blocks of code?
To identify blocks that may throw exceptions and to cleanly handle exceptions if they are thrown
To advertise to the user that the program may not work correctly
To identify and process experimental code that extends beyond the C# language
To re-run risky code over and over again until the correct result is produced
What happens by default if a Unity script throws an exception?
The Unity engine will catch it and display the exception message to the console
The game will crash immediately
The game will run more slowly
The user is prompted to request a refund
.How can you get Unity to tell you exactly where an exception was thrown?
Double-click on the red exception message in the Console
Select Debug, then Exceptions, then Locate from the menu
Right-click on the red exception message and select "Properties"
View the exception in the Inspector panel
When an exception is thrown, what two useful pieces of information are you given?
A description of the exception and the specific line of code that threw the exception
A description of the exception and a recommendation for how to fix it
The number of times the exception has happened and the resulting impact on your program
The specific line of code that caused the problem and a specific fix for that line of code
Which of the following is NOT a recommended approach for finding and fixing run-time behavioral problems in your code?
Run the program repeatedly until you can guess the solution
Conduct a code review
Add program trace statements to help understand the flow
Use a debugger to study your program as it runs
Which of the following steps should be part of a code review?
All of these are true
Review your variables and make sure they are initialized
Review each function to understand when and how it is called
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
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"); }
The logical expression doesn't match the intent of the rest of the program logic
The Debug.Log() statements will both execute
A compile-time error will prevent it from building and running
There are no problems with this code
Using a code review, what is the problem with the following code?
GameObject myObject;
Debug.Log("My name is " + myObject.name);
An exception will be thrown on the second statement
An exception will be thrown on the first statement
The Debug.Log() statement may print random information
Nothing, this code will work fine
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?
The mystery2() function did not complete successfully
The mystery1() function did not complete successfully
Neither mystery1() nor mystery2() completed successfully
Both mystery1() and mystery2() completed successfully
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?
This block of code was not executed at all
The mystery1() function started but did not complete successfully
Both mystery1() and mystery2() threw an exception
The mystery1() function completed but the mystery2() function did not
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?
You can't tell if the logical expression in the if() statement is correct
You can't tell if the input data to the calculatePrice() function is correct
You can't tell if the calculatePrice() function completed and returned a valid price
You can't tell any of these things from the tracing statements that were added
Where do you enable the Unity debugger that will let you watch a running program line-by-line?
From the Visual Studio toolbar or menu
From the Unity IDE menu
The debugger is a standalone program you run by double-clicking on it
All of these will work
Which of the following things must be done before you can use a debugger to study your program?
Enable the debugger
Manually run the game from the Unity IDE
Both of these things must be done
Neither of these things must be done
How do you add or remove a breakpoint to a line of code?
Click in the gray column to the left of the line or use the "Run" menu
Add or remove the "breakpoint" keyword in front of a line of code
Attach a breakpoint component to the script in the Unity IDE Inspector
Breakpoints are set automatically when exceptions are thrown; you can't configure them yourself
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?
mystery2();
mystery1();
mystery3();
It is impossible to tell
Which of the following debugger commands will let you enter a function and examine the individual lines within the function?
Step Into
Step Over
Step Out
Continue
.How can you examine current variable contents when a program is in break state in the debugger?
Look at the Locals tab
Hover the mouse over the variable name to get a temporary pop-up
Pin a variable pop-up to the screen so it will stay visible
All of these will work
