14.10 Errors and error handling in file operation
Programmers tend to be optimistic. They feel errors will not occur in a program. However, a good programmer will not assume such a thing. When we work with files we should imagine what types of errors may occur and write such a code that takes care of them.
- Attempting to open non-existent files
When we try to open a file either by associating with a file stream or using open function the operating system looks for the file in current directory. If the file does not exist it is clearly an error. The file opening operation fails.
- Trying to open a file with invalid name
This situation can also occur sometimes. You want to open a existing file, but you misspell it. (Let us assume that there is no ...
Get Object Oriented Programming with C++, Second Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.