Sorry, but exceptions have me lost. I understand the basic try, throw, catch, but in trying to understand it better I have become frustrated and you guys always seem to get me headed in the right direction. So just a brief summary of the project.
We are supposed to manipulate an array of Student records. I have a custom string class & and an Array Template Class. I also have a Names class which uses the String Class; and an Address Class which uses a DigitString class inherited from the String Class but only accepts digits. Then there is a Student Class that uses the Name, Address, & Array Classes. Then in main, I tie it all together using the Array Template to hold the collection of Students.
This goes beyond what is required, but I would like to add an exceptions class to handle the exceptions that I anticipate might be thrown; such as INDEX_OUT_OF_BOUNDS_EXCEPTION, NON_DIGIT_EXCEPTION, etc.
kind of where I am heading is:
class MyExceptions
{
enum Exceptions {INDEX_OUT_OF_BOUNDS_EXCEPTION, NON_DIGIT_EXCEPTION};
MyExceptions (0); //From anywhere that included this header I could throw the INDEX_OUT_OF_BOUNDS and have it caught here.
MyExceptions (1); // From anywhere that included this header I could throw the NON_DIGIT_EXCEPTION and have it caught here.
};
Is this making any since at all? Please excuse my ignorance on this subject. I have done some searches and I just can't get it to click.
You can't designate where exceptions are caught. All an exception class does is it acts as a container to hold data relating to the exception. The exception itself is always caught in the catch block:
1 2 3 4 5 6 7 8 9 10
try
{
//...
// if any exception is thrown here
//
}
catch(...)
{
// it will be caught here
}
You cannot have an exception caught by a designated function like that. It's always caught by somewhere higher up in the call stack.
I really don't know how to convey my question correctly. I have to miss class tomorrow for work and was hoping to get some help sooner. But I will pose this in class on Thursday and maybe my instructor can decifer my gibberish a little better face to face. I will post back later on. Thanks for replying.