0:00
Hey guys, this chapter covers the concept of exceptional handling
0:10
So what does it really mean? Well, the exceptional handling is the process of handling any type of errors that might
0:18
arise during program execution. So we as programmers have to handle them and when some statement has the possibility to
0:26
arise an error, we simply display a message to the user or perform any other activity
0:33
before even the error hits so the end user has not to worry about any errors during the
0:40
runtime of a program. Before we dive into program examples, we need to understand some important keywords
0:49
We mainly use four keywords associated with exceptional handling. Try The try keyword is what lets you to test a
0:59
block of code for errors. Exception The exception keyword helps you handle the error
1:08
Else The else block will be considered when there are no errors
1:13
Finally The finally block contains a statement or group of statements that has to be executed regardless of the result of the try and exceptional blocks
1:27
Example 1 A program that divides two given numbers num1 equals to 5 num2 equals to 0
1:38
try print num1 divided by num2 except print the denominator should not be 0
1:51
Example 2 In this example, the except block doesn't execute. Try print hello except print something went wrong
2:04
else print nothing went wrong Example 3 So now we're trying to open a text file
2:17
Try f equals to open testing.txt except print the file not exists
2:29
else f.write hello world print done Finally, f.close print finally closed
2:44
Try practicing exceptional handling yourself so you can get better in handling any type
2:50
of errors. That was all. Thanks for watching