Final thoughts
It's important to reiterate that exceptions don't always have to resolve errors. Since they function like if...else blocks, they can be used in a similar manner. For example, the end-of-file exception (EOFError) can be used to identify when the last line of a file has been processed, thereby breaking out of the processing loop.
One possible use of this is to analyze strings. If a string method won't work for you, you can generally accomplish the same goal using exceptions. For example, if you want to determine if a string value is a float, you can't use the str.isdigit() method to do the job; it can only tell you if a particular string entry matches the values 0-9. If you have a floating-point number, which includes a decimal ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access