Exercises, examples and other material relating to training module C236. This topic is presented on public courses Learning to program in C and C++
, C++ for C Programmers
, C and C++ Programming
, Learning to program in C and C++
, C and C++ Programming
Error checking - anything from checking that the user has
entered a valid respones to a question through to ensuring that
a remote system you need to contact is available - is a vital
part of any program. Sometimes, you can easily check things
with a few if statements, but at other times it's much more
practical to use an exception system where you call for a piece
of code to be run, but then branch off to a particular handler
is a certain condition is triggered.
Related technical and longer articleserrors v exceptions
|Articles and tips on this subject||updated|
|3509||Operator Overloading, Exceptions, Pointers, References and Templates in C++ - new examples from our courses|
I've added three new C++ examples to our library following on from last week's C++ course. Each of them is one step beyond "hello world" with regard to the particular feature it's showing, but isn't so advanced and showing so many options that it confuses the newcomer - at least that's the theory. ...
|3068||Throwing your own exception in C++, and catching it|
In C++ you can throw anything - it doesn't have to be something "throw-able" as in Java.
1. Create a class of objects that you want to throw in exceptional circumstances
2. When you want to throw an exception, use the throw keyword and pass in the object
3. Call the code that you want to catch the ...
|2622||Handling unusual and error conditions - exceptions|
"I can't answer that question in the way you expect" ... that's something that may be said to you occasionally - you ask someone what suit a playing card is that they're holding and they cannot tell you because it is a joker, or you ask what number is written on a piece of paper when the paper is blank.
|1875||What are exceptions - Python based answer|
How do you check for run time errors in your program? You'll include tests with if statements in almost every program you write, to ensure that user entered data is reasonable / as you would expect ... but you will also need to do more that that. You'll need to check whether a system function has run ...
|799||The case for exceptions|
When you run a program, things can go wrong - run time errors. And no amount of coding by the programmer can prevent these things - it’s a user entering a string of text when a number’s required, a needed file having been deleted, or a network connection that’s broken that causes probems.
Examples from our training material
|CppExcept.cpp|| Creating exception objects, throwing and catching them|
|except.cpp|| Exception handling - catches|
|levels.cpp|| Exceptions - try, catch yourself AND throw to parent too|
|makefile|| Compile / Load instructions for examples in this module|
|microthrow.cpp|| Defining, throwing, catching an excpetion|
|prob.cpp|| Exception handling - why we need it|
Some modules are available for download
as a sample of our material or under an Open Training Notes License
for free download from [here]
Topics covered in this module
What are exceptions?
Try and catch.
Accessing exception data.
Throwing your own exceptions.
If you are looking for a complete course and not just a information on a single subject, visit our Listing and schedule
Well House Consultants specialise in training courses in
. We run
throughout the UK (and beyond for longer courses), and
at our training centre in Melksham, Wiltshire, England.
It's surprisingly cost effective to come on our public courses -
even if you live in a different
country or continent to us
We have a technical library of over 700 books on the subjects on which we teach.
These books are available for reference at our training centre.