www.digitalmars.com         C & C++   DMDScript  

D - Throwing exceptions in Array List ADT

reply "Andrew Edwards" <edwardsac spamfreeusa.com> writes:
Hi guys,

I've actually start taking C++ programming classes again (first time since
1995) to prepare for the inevitable! (D)

I'm trying to implement an Array List ADT from which I've got to throw
bad_alloc and logic_error exceptions.  I've pretty much completed the
implementation, however I am having a little bit of a problem understanding
this concept.  Would someone mind explaining and demonstrating how to use
throw to guard against overrunning the array in the following insert
function?

void List:: insert ( const T &item ) throw ( logic_error )
{
  if ( !Full() )
  {
    container[ ++position] = item;
    size++;
  }
  else
    return;
}

Andrew
Jun 04 2003
parent "Walter" <walter digitalmars.com> writes:
It will automatically throw an ArrayBoundsException, no extra coding
necessary.

"Andrew Edwards" <edwardsac spamfreeusa.com> wrote in message
news:bbk9kf$2r14$1 digitaldaemon.com...
 Hi guys,

 I've actually start taking C++ programming classes again (first time since
 1995) to prepare for the inevitable! (D)

 I'm trying to implement an Array List ADT from which I've got to throw
 bad_alloc and logic_error exceptions.  I've pretty much completed the
 implementation, however I am having a little bit of a problem
understanding
 this concept.  Would someone mind explaining and demonstrating how to use
 throw to guard against overrunning the array in the following insert
 function?

 void List:: insert ( const T &item ) throw ( logic_error )
 {
   if ( !Full() )
   {
     container[ ++position] = item;
     size++;
   }
   else
     return;
 }

 Andrew
Jun 16 2003