Welcome back.
We learn about dictionaries.
Now we're going to learn about error handling.
Sometimes your code might cause an error dividing by zero or converting bad input.
Instead of crashing, use try and accept to handle errors gracefully.
Let's start with this example.
Try Num1 float.
It's of type.
Enter a number.
Number two it's of type float input.
Enter another number.
Result Num1 over Num2.
We are dividing Num1 over Num2 and print the result.
Here, if I entered zero for the second number, it will give me an error because and the error that
the application crashes.
But since I'm using try and accept here we can throw an exception which is zero division error or value
error.
Please enter valid numbers.
Let me run.
I'll show you and clarify everything.
The first number, for example 15.
The second number is three.
The result is 5.0.
This is good.
Let me run again.
Enter a number 15.
The second number is zero.
Click enter.
And can't divide by zero.
This is an exception thrown by this cell because we have used the try and except.
Try.
We are trying the program.
Any error.
Go and throw those exceptions and don't allow the application to crash.
Let me run again.
Enter a number.
For example 15.
Enter another number.
If the user by mistake enters a string, here we have another error.
Please enter a valid number.
So this exception is being thrown when the user enters a string or an invalid invalid data.
Let me run again.
For example 15 six G enter.
Please enter valid numbers.
So this is how we handle in the exceptions.
How we handle errors gracefully instead of crashing using try and accept.