From the course: Learning C#
Unlock the full course today
Join today to access over 24,800 courses taught by industry experts.
Exceptions
- [Illustrator] Just like in life, sometimes things go wrong in our programs and it's necessary to handle those conditions so that the user doesn't get a bad experience. In C#, like in some other languages, we use a programming technique called exception handling to catch errors before they make their way to the user. So let's take a look at how this works. Here in my code in the exceptions folder, I'll open up the Program File. So here in my example code. I have a few variables with some values and I'm going to do a simple math operation. I'm going to assign the result to the value of X divided by Y. So that works fine, just as long as I don't try to do something foolish, like divide by zero. So let's make that change and see what happens. So I make y zero and save this and let's go ahead and bring up our terminal, and what I'm going to do is run this now. So when I run the code, I think that's going to try to…
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.