Module 5: Error Handling and Debugging Flashcards

1
Q

What is a syntax error?

A

A syntax error results from a programmer incorrectly typing in the sequence of characters or tokens to be used in a statement in a programming language.

Syntax errors are typically caught at compile time, but most modern integrated development environments (IDEs) implement features that monitor the code as the programmer types it in, performing syntax error checking and informing the programmer about syntax errors before he or she even attempts to compile the code.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are logic errors?

A

A logic error is an error in your algorithm, which causes the algorithm to not work as intended and thereby not solve the problem at hand. Logic errors are the most critical type of errors in your program code. This is because logic errors can be extremely difficult to find.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is structured exception handling?

A

It is when you control the alternate flow of execution. Run error handling to: correct the error, notify the user in case they can correct the error, execute clean- up code after the exception.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is an exception?

A

It is an event in your application that occurs when something goes wrong. Exceptions cause a change in the flow of execution in your code. If you do not handle the exceptions, the change of flow typically results in the application crashing.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is a DivideByZeroException?

A

If your code attempts math division by 0.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is an InvalidCastException?

A

When trying to cast from one base type to another, such as casting an object to a string.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is and IndexOutOfRangeException?

A

It happens if you attempt to access an element of an array with an invalid index parameter.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What are catch blocks?

A

It is code that trap any errors that may occur.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is a finally block?

A

After an error has been generated and handled, the finally block will still execute before returning the execution back to the application or to the computer. You want this to happen in the event you have a file open and you need to close it before the application ends.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is throwing an exception?

A

Throwing an exception is generally what you do when you want the exception to be handled in some location other than the current location in code.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is a try block?

A

It is the component of structured exception handling that sets up a piece of code to be monitored for any exceptions that might occur. As MSDN refers to it, the try block contains guarded code. Guarded code is code that might cause an exception.

EX:
try 
{ 
   // guarded code 
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is a catch block?

A

Is responsible for identifying and handling specific, or generic, exceptions. It is where you will specify the exceptions that you want to catch.

EX:
static void Main(string[] args) 
{ 
   string errorMessage; 
   try 
   { 
      // Some math functionality here 
   } 
   catch(OverflowException ofEx) 
   { 
      errorMessage = ofEx.Message; 
   } 
   catch(DivideByZeroException dEx) 
   { 
      errorMessage = dEx.Message; 
   } 
   catch(Exception e) 
   { 
      errorMessage = e.Message; 
   }
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is the finally block?

A

It is the location where you will close the file handle, releasing the resource.

EX:
static void Main(string[] args) 
{ 
   try 
   { 
      // Some code to open and access a file here 
   } 
   catch(IOException ioEx) 
   { 
      errorMessage = ioEx.Message; 
   } 
   finally 
   { 
      if(file != null) 
      { 
         file.Close(); 
      } 
   } 
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is the exception handling mechanism?

A

Catches specific exceptions first; uses exception class as final catch-all; cleans up in Finally.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is the recommended design strategy for catch blocks?

A

To place the more specific catch blocks first and the more general catch blocks later.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

If you are not sure what exception may be thrown during testing what should you do?

A

Use the generic Exception class to ensure that you do catch any and all exceptions. Then, log them during the testing, and then review the error logs to determine what, if any, more specific exceptions you should catch.

17
Q

What is debugging?

A

Can be classified as the process of identifying and reducing the number of defects in a program’s code.

18
Q

How is debugging accomplished?

A

It is accomplished through software testing. Software testing is accomplished by actually running the compiled application on the intended platform and having testers or end users use the application in the way it is intended and also in ways it is not intended. The purpose of these tests is to see if there are issues that will surface outside of the development environment which you didn’t think about.

Debugging in Visual Studio revolves around using the features built into Visual Studio such as the squiggly underlines in the code editor that appear when you type your code and the debugger that you can use while compiling and running your code.

19
Q

What is the debugger in visual studios?

A

The debugger uses breakpoints to pause code execution, provides features to step through code and offers windows to view variables and call stack.

20
Q

In the debugger window what is the Call Stack?

A

The call stack window displays information about method calls and instructions that are currently on the stack when the error occurs. This helps you trace out an execution path allowing you to see where the code is being called from and the order in which instructions are being executed.

21
Q

In the debugger window what are Breakpoints?

A

Breakpoints window shows you all the breakpoints in your code, what line they are on, the current character in that line, and labels, conditions or hit counts. Also it allows you to search for breakpoints.

22
Q

What are Command Windows?

A

Command windows are used to execute commands directly in the IDE. You can evaluate expressions by using the question mark such as “? myVariable”, perform evaluations between variables such as comparisons, and even edit and replace text in the files in the project.

23
Q

What are Immediate Windows?

A

Use these windows to debug and evaluate expressions in your code, execute statements such as “Debug.Print myVariable” to output the value of a variable that you want to check, and issue Visual Studio commands to assign values to variables. It’s called the Immediate windows because what you type in here, executes immediately when you press ENTER.

24
Q

What is the Output Window?

A

This window displays status messages from Visual Studio as it relates to the currently running program. This window displays messages about exit codes on application threads and the name of the executable files that are being monitored and reported on.

25
Q

What is the Autos Window?

A

This window displays the names of all the variables that exist in the current and previous statements in the code window. You will be able to see the values of these variable along with the type of the variable. The variables in this window change as the code lines change. That is why it is called Autos for automatic variables.

26
Q

What is the Locals Window?

A

The Locals window also shows variable names, types, and values similar to the Autos window. The only exception is that all variables that are in scope are also displayed. Scope refers to where in code the application can see a variable. After the function goes out of scope, so do the variables and they will no longer be displayed in the window.

27
Q

What is the Watch Window?

A

This window allows you to specify variables that you want to monitor during execution of the debug session. You can also edit the values of the variables in this window.

28
Q

What is Stepping Through Code?

A

After the code execution is paused and you have chosen the debug windows you want displayed, you can begin the actual debugging process by stepping through the code. Visual Studio allows you to step through the code one line at a time, step over a piece of code, or step out of a procedure.

29
Q

What is “Step Into” and what is it used for?

A

Using the Step Into button on the toolbar or pressing F11 on the keyboard, you can step through the code, one line at a time, starting from the breakpoint. This is the finest control you have over the code execution flow during debugging.

Use Step Into to help you troubleshoot variable values, code logic, assignment statements, and so on. This option also allows you to see exactly how the code executes and how the values are affected by the logic. This helps you identify errors in loops, decision structures, comparison operations, and many other code errors.

30
Q

What is “Step Out” and what is it used for?

A

When debugging code and using the stepping commands, Step Out executes the remaining lines of code in a function, all without your intervention. The execution will continue through the end of the function and then stop on the next line of code after the function ends. This is useful when you know that the rest of the function works fine and you want to continue debugging without stepping over each remaining line of code in that function, one at a time.

31
Q

What is “Step Over” and what is used for?

A

This command causes Visual Studio to execute the whole function or procedure as a single unit and then to stop at the next statement. If you have a function that you know has been debugged or is working correctly, you can step over that function rather than executing it one line at a time. The code in the function is still executed, it’s just that you won’t step over each line of code.