From the course: Transition from C# to Python

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Exceptions

Exceptions

From the course: Transition from C# to Python

Start my 1-month free trial

Exceptions

- [Instructor] Like other modern languages, Python supports exceptions. And the syntax is slightly different from C# but the basic structure is the same. So let's go into our exceptions folder and open up the exceptions C# version first. And let's scroll down. So here in this sample C# program, the code attempts to divide two numbers and you can see that there are exception handlers are defined to catch a divide by zero exception and argument out of range exception. And there's a more basic exception for anything else. And of course, there's also a finally section whose code always runs whether there was a problem or not. So if we run this current code, let's go out to the terminal and let's go into exceptions and let's go into exceptionsCS. Oh, oops. Let's go into exceptionCS, and we'll run this. And you can see that when the current code runs that everything works. So now if I change the denominator to zero. So if…

Contents