MMmmmmk so what i am trying to do is simply throw a the ERROR object from the Array<T>::operator[] and catch it in main take a took... it prints out the equivalent of an empty space in memory.

//error.h
class ERROR
{
public:
	ERROR(char * Incomming)
	{
		m_message = new char[strlen(Incomming)+1];
		strcpy(m_message, Incomming);
	};
	void GetMessage(){std::cerr<<m_message<<std::endl;};
	~ERROR(){delete m_message;};
private:
	char * m_message;
	

};

//array.h
template <typename T>
T &Array<T>::operator[](int const &index)    //throw(ERROR) doesn't work
{
	int newindex = index - m_start_index;

		if(newindex == m_length)
			throw ERROR("Out Of Bounds");

	return m_array[newindex];
}

//main.cpp
for(int i(arrInt2.getStartIndex()); i<arrInt2.getLength()+arrInt2.getStartIndex()+1; i++)
{
	try{std::cout<<arrInt2[i]<<" ";}
	catch(ERROR *er)
	{
	        er->GetMessage();
	}

}

anything you guys see?

don't try to catch a pointer to the object, because you have thrown the ERROR object (not a pointer to the ERROR object).

use catch(ERROR &er){er.GetMessage();} in the main code.

you could also use catch(ERROR er){er.GetMessage();} in the main code.

its just a pointer because i was swapping em out, trying const ref, ref, value, pointer etc and it just ended up at pointer when i posted... but i made the ERROR class canonical and it worked thanks!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.