I have the following types:
typedef QPair < QTime , QTime > CalculatedTimeSlotRange;
typedef QList < CalculatedTimeSlotRange > CalculatedTimeSlotRangeList;
typedef QHash < quint8 , CalculatedTimeSlotRangeList > TimeSlotsTable;
I have a function like the following:
const CalculatedTimeSlotRangeList* TimeSlots::getCalculatedTimeSlotRangeList(const quint8 id) const
{
QHashIterator<quint8,CalculatedTimeSlotRangeList> it(mTimeSlotsTable);
while (it.hasNext()) {
it.next();
if(it.key() == id) {
return &it.value();
}
}
return NULL;
}
as you can see my function returns a NULL
if it fails to find a key that matches id
. Is this correct? or should I just throw an exception if the key does not exist? how should i throw an exception for this situation?
EDIT:
after seeing the comments and the answer I thought it's important to point out that it doesn't matter if an exception is thrown or the null is returned. This event implies incorrect parameters which are supplied to program through a number of files. The program must display an error message and ask the user to replace the parameter files with correct ones. So what is the better choice here? exception or null pointers since both of them mean the same thing in this context. Please edit the question and description if it fails to reflect my actual intention.