From the course: A Start to Using Generative AI in .NET
Unlock the full course today
Join today to access over 24,000 courses taught by industry experts.
Error handling - .NET Tutorial
From the course: A Start to Using Generative AI in .NET
Error handling
- [Instructor] Having a functioning chat bot is great, but if you're an experienced developer, you know that things don't always go as planned. Let's discuss how to detect and handle errors in our little chat application. Looking at the code, the first thing that pops out is that we are assuming that the environment variable OpenAI API key is set. If it's not, the code will throw an exception. Let's fix this. I'm going to change it so that it allows no values. And then we are going to say if string that is null or empty key, then we are going to do the thing, console.writeline, please set the OpenAI API key environment variable period. And then we're just going to quit the application because there's nothing we can do at this point. Okay, let's try it out. I'm going to change the environment variable slightly so we don't have this, run the application and seems like it works. We do have the error message that we wanted. Okay, let me change the environment variable back and let's go…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
Choosing a .NET library3m 37s
-
(Locked)
Creating a basic .NET Core console application3m 42s
-
(Locked)
Create the OpenAIClient object5m 17s
-
(Locked)
Hello chat6m 25s
-
(Locked)
The chat loop5m 19s
-
(Locked)
Error handling7m 35s
-
(Locked)
Using the Azure OpenAI service5m 35s
-
(Locked)
Streaming vs. non-streaming2m 43s
-
(Locked)
Implementing streaming completion7m 18s
-
(Locked)
Challenge: Fix the bugs41s
-
(Locked)
Solution: Fix the bugs6m 40s
-
-
-