just one of my functions isn't throwing exceptions for some reason. this one doesn't work:
Code:
void list::insert(const plane& p) throw(listException)
{
int i = 0;
if (size >= MAX_LIST)
throw listException("List is full"); // <--doesn't work
while (i != size && planeList[i] < p)
i++;
if (i != size && planeList[i] == p)
throw listException("Duplicate plane - not inserted."); // <-- doesn't work
//right shift
for (int pos = size; pos > i; pos--)
{
planeList[pos] = planeList[pos - 1];
if (pos < 1 || pos > size)
throw listException("Bad index on insert"); // <-- doesn't work
}
planeList[i] = p;
size++;
}
but it works over here in this function:
Code:
void list::remove(const plane& p) throw(listException)
{
int i = 0;
if (size == 0) //list is empty?
throw listException("List is empty"); //<-- works
while (i != size && planeList[i] < p)
i++;
//left shift
for (int pos = 1; pos < size + 1; pos++)
{
if (pos >= i) //dont move any to the left of i
planeList[pos] = planeList[pos + 1];
}
//display no delete if input is invalid
if (planeList[i] == p)
cout << endl << "Plane successfully deleted." << endl << endl;
else
throw listException("List is empty"); //<-- works
size--;
}
i dont get it.....here's the listException class
Code:
//Filename: listException.h
#include <cstring>
#pragma once
using namespace std;
class listException
{
public:
listException(const char msg[] = "")
{
strcpy(message, msg);
}
const char* what()
{
return message;
}
private:
char message[50];
};
here's the call
Code:
//....
case 2:
//delete a plane
p = getModelAndNumber();
try
{
l.remove(p);
}
catch(listException ex)
{
cout << endl << "Exception Occurred: " << ex.what() << endl << endl;
}
break;
//....