Intermediate Business Programming with C++

Introduction to Handling Errors

Each program that you write should be designed to handle errors. One way is to let the program terminate without handling the error. This is in general an unsatisfactory approach. The error should be handled so that if the program must terminate, it terminates in an orderly manner. There are several ways to handle errors and the method depends on the type of error.

Programmers and in particular C or Classical C++ programmers typically handled errors by:

If you are interested in the last four, I recommend you read a book on C because they will not be discussed in these lectures. Instead we will devote our time to a new way in Standard C++ that was created to handle errors called exception handling techniques. This lecture will only be an introduction to error handling with a brief introduction to the topic of exception handling of errors.

By exception handling is meant handing runtime errors caused by abnormal conditions. But these techniques do not handle all errors. C++ exception handling should not be used for:

With exception handling, general errors are taken care of in a general way. These errors are not taken care at the location of where they occur. C++ exception handling should be used for synchronous errors like:

Exception handing permits development teams to create sub teams who will work solely on error handling by using a better and more organized approach. These methods not only work in single threaded OS but also in multiple threaded OS like Windows and Unix. While error handling is an important feature that needs to be considered, the programmer must be careful not to overburden the program with an excessive amount of error handling. Where that line is between excessive and just right will only come with experience. It will also depend on the type of programs written.

Hopefully those who write programs for atomic power plants, heart monitors, aircraft guidance systems, corporate accounting systems and other critical software will use an excessive amount of error checking.

Категории