C++ Xcode OOP Exceptions Primer Tutorial

C++ Xcode OOP Exceptions Primer Tutorial

C++ Xcode OOP Exceptions Primer Tutorial

Our C++ Xcode OOP Exceptions Tutorial presented here opens the door to the idea of handling error exceptions when using C++. The two major areas I’ve found where error handling is really important are with mathematical calculations and with input/output scenarios (which includes file handling). Let’s see below some information about Exception Handling from Wikipedia:

Exception handling is the process of responding to the occurrence, during computation, of exceptions – anomalous or exceptional events requiring special processing – often changing the normal flow of program execution. It is provided by specialized programming language constructs or computer hardware mechanisms.

In general, an exception is handled (resolved) by saving the current state of execution in a predefined place and switching the execution to a specific subroutine known as an exception handler. If exceptions are continuable, the handler may later resume the execution at the original location using the saved information. For example, a floating point divide by zero exception will typically, by default, allow the program to be resumed, while an out of memory condition might not be resolvable transparently.

Alternative approaches to exception handling in software are error checking, which maintains normal program flow with later explicit checks for contingencies reported using special return values or some auxiliary global variable such as C’s errno or floating point status flags; or input validation to preemptively filter exceptional cases.

Click on picture to see some C++ using XCode programming showing an error handling scenario where we act in a proactive way to circumvent any errors to do with finding the cube root of a negative number (using the throw method), and then looking at two mathematical checks which are not error throwers (via use of isnan and isinf) leaving default try/catch exception logic for other scenario types.

Link to some downloadable programming C++ source code … rename to main.cpp for use.

Link to Exception Handling information … from Wikipedia from which quote above comes.

If this was interesting you may be interested in this too.

This entry was posted in eLearning, OOP, Tutorials, Xcode and tagged , , , , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *