returning null or throwing an exception?
- by MoKi
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?