I am trying queue implementation in c++. During that I am having this problem.
void Queue::view()
{
int i;
try
{
if(Qstatus==EMPTY)
{
UnderFlowException ex = UnderFlowException("\nQUEUE IS EMPTY");
throw ex;
}
}
i=front;
cout<<"Queue contains...\n";
while(i <= rear)
{
cout<<queue[i]<<" ";
i++;
}
}
This gives an error as :
error: expected ‘catch’ before ‘i’
I think this problem is arises since I doesn’t written catch block below try block.
But If want to write the catch block in main(), ( like in this case ), how could I do that?
Before, that Could I do that? If not Why?
catchblock must follow thetryblock. If you want thecatchto be inmain– that’s where thetryhas to be too. You canthroweverywhere, doesn’t have to be inside atryblock within the same function.It should be something like this: