Introduction
C# developers are responsible for code debugging and exception handling in their applications. The C# language supports exception handling patterns such as the try-catch
and try-catch-finally
patterns. Visual Studio Code uses extensions to support code debugging. You can find debugger extensions in the Visual Studio Code Marketplace.
Suppose you're part of a team that's developing retail-support applications. The team is working on a cash register application that manages retail transactions. You're developing the MakeChange
method that manages the money till and calculates the amount of change returned to the customer. The MakeChange
method tracks the number of bills of each denomination (1, 5, 10, and 20) that are available in the till. The team is planning to add exception handling to the application during the code verification process.
This module guides you through a code review and debugging process where exception handling is also added to the application.
By the end of this module, you're able to debug a C# application using the Visual Studio Code debugger, implement a try-catch
pattern, and throw exceptions that are caught at a lower level of the call stack.
Note
This is a guided project module where you’ll complete an end-to-end project by following step-by-step instructions.
Learning objectives
In this module, you practice how to:
- Use the Visual Studio Code debugger tools to identify and correct an issue in your code logic.
- Implement exception handling in a C# console application using the
try-catch
pattern. - Create and throw exceptions with customized properties.
- Catch exceptions at a lower level in the call stack.
Prerequisites
- An installation of Visual Studio Code that's configured for C# application development.
- Ability to develop C# console applications that implement business logic using iteration statements, selection statements, and custom methods.
- Experience using the Visual Studio Code debugging tools for C#.
- Experience implementing
try-catch
exception handing and throwing exceptions in C# console applications.