From the course: C# Exception and Error Handling

Unlock the full course today

Join today to access over 24,800 courses taught by industry experts.

Solution: Basics

Solution: Basics

- [Instructor] All right, so how did you do? Were you able to handle the different exceptions? Let's take a look at my code. So the first part of my solution is the same as the starting point that I provided for your challenge. I've defined a few local variables to use. And so here I have the code that reads in the user input. All right. And let's see, if we scroll down a little bit. This is where the challenge part was. So I needed to convert the string to a number and then perform the operation that I was told to do. So I enclosed my code in a try block. And the first two operations here, the first two calls to Parse are to convert the strings that the user entered up here in the calls to the ReadLine. And I'm doing that using the Parse function. Now, as I showed in the documentation, this function may throw a FormatException. So I catch that FormatException as my first catch block. And then I write out the message that the exception comes along with. We already saw how to handle…

Contents