From the course: Debugging in C#

Unlock the full course today

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

Logical errors

Logical errors

From the course: Debugging in C#

Start my 1-month free trial

Logical errors

[Instructor] In our code, we can also have other types of logical errors. Logical errors are only caught during program execution. One type of logical error is dividing by zero. The operation of dividing by zero is an invalid operation and as a result, our program errors and throws an exception. Let's take a look at an example of this in code. In this program, we have an int A that has the value of four and int B that has the value of zero and then, we divide the two values and store the value in results. Let's run this and see what happens. So here, we get a system divide by zero exception. We attempted to divide by zero. This operation is invalid and the only way to avoid this error is to not divide by zero. But, we can capture this error and handle it in a different way with C sharp's exception handling features. These features help you deal with unexpected or exceptional situations that occur when a program is running. Exception handling uses the try, catch, and finally key words…

Contents