

Print("I have reached the end of the line") values of a and b are taken from userĪt this time, there's a high probability that the user will give 0 as the input to b.
CODE BLOCKS AN EXCEPTION HAS BEEN RAISED CODE
If the values of a and b are hard-coded, then running the code will solve this error to some extent.īut the other major problem that may arise is when a user wants to give values of a and b at the time of execution. One of the naive solutions to solve this problem can be hard coding the values. At this point, it raised an error in the console and exited the code. Well, because the Python interpreter stopped at line 3 when the a got divided by 0. Even though the code didn't print the result value, it should have printed I have reached the end of the line. The above error messages displays division by zero, which means that if we try to divide any number by 0, we will get this error.

The code didn't print the result value and it also didn't print I have reached the end of the line When this code gets executed, we will get an error as below: Error message displayed when b is set to 0 print("I have reached the end of the line") Program with error Let's change value of b from b = 6 to b = 0 and run. Well, the result variable prints 2.0 and on the next line, the console prints I have reached the end of the line. Print("I have reached the end of the line") Program with no errorįrom the above code, what do you expect ?. Let's take an example and understand why we need error handling: a = 12 If errors occur in any lines of code, the error handling takes care of them and then the code resumes execution. Handling or taking care of errors that you're aware of helps the code flow and execute smoothly without any interruptions. In fact, while writing programs, errors can be really helpful in identifying the logic bugs and syntax errors in your code.īut, if you can anticipate an error in a particular set of code lines before execution, then you can handle those errors and make the code error free. “It’s hard enough to find an error in your code when you’re looking for it it’s even harder when you’ve assumed your code is error-free.”Įrrors are inevitable in a programmer's life.
