One of the common patterns when working with files is to actually put them in a try except block.
So in here we can say try and actually put them.
Like this and try out to see if the file exists so we can say except.
And let's say.
File not found error, which we've seen before.
And here, I can say as air and inside will say, print file does not exist.
So that now if I run this and remember in our current directory, we don't have said dot text if I run
this.
I get an error file does not exist, we can even raise this error if we want to do so, we can say raise
error.
So now it works as expected.
I'll get fouled does not exist and then give a file not found error.
So this is a common way to work with files to handle different errors.
Another common one with.
Philes, is this idea of an IO era and an era usually happens when the computer or the machine you're
on has some issue reading or writing or doing any sort of Eyo operation.
So you can have something like WHIO error in here and raise that er if you want.
Again, if I run this file not found there.
If for some reason I give it a weird mode to do.
I get an unsupported operation or the options are endless, but I hope by now you have an idea of how
to do fall ill, but let's do a fun exercise, because up until now, we haven't really done anything
exciting.
We just read a bunch of text from a file and that was it.
Nothing that creator.
Right.
So let's do something fun.
In the next video, we're going to try and build a translator.
That's right.
I'll see in the next video.