Try-catch

I have finished this code that is supposed to remove an from an array if it within the number of strings in the array, otherwise it is supposed to throw an exception. The code does it's job when removing, but does not throw an exception. I figure that I have not written the code correctly, so can anyone help me figure out where I went wrong?
1
2
3
4
5
6
7
8
9
10
11
12
void EndlessSortedArray::remove(int index){
    try{
	if(index < numStringsInArray){
	    for(int i = index; i < numStringsInArray; i++){
		sortedArray[i] = sortedArray[i+1];
	    }
	    numStringsInArray--;
	}
    } catch(exception& e) {
	cout << e.what() << endl;
    }
}


I have tested it by entering 14 for index while the numstrings is equal to 9 but nothing happens. Anyone have an idea?

Thanks,
Chris

Edit: I have included the stdexcept and the exception classes
Last edited on
Throwing an exception is generally done with the throw keyword.
I feel like a fool now. Thanks for replying, I have fixed it.
Topic archived. No new replies allowed.