"Writing exception-safe code in C++ is fundamentally about writing try and catch in the correct places." Discuss.
Well, what do you know about exception handling and the try and catch system?
I understand that exception handling is a way of processing or handling synchronous error, such as bad allocation, invalid parameter, and other error that occur during the execution of the normal flow of a program. So i want to know more about it.
Basically it means this: Try to do some command. If the command fails, do this instead! Here is a more detailed example of using this: Lets say you want user input. You need an floating point number. But the person types a letter. This would cause a bad assignment and crash the program. Rather than let this happen, you do a try-catch sequence and change any errors into a new request to the user or some sort of help message. Another good use is to do a try-catch around file IO. Lets say you want to open a file to write. However, what if the system has marked the file as in use or read only? By doing a try-catch, you can detect the failed opening of the file and tell the software to look for reasons for the failure.
Join our real-time social learning platform and learn together with your friends!