954,483 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Error Handling

So my Turbo C doesn't handle errors. And in school we used VC++ but I don't have it at home. So can anyone tell if the code snippets for Queue and Dequeuing a Queue and Pop and Push operations in Stack are right?

\int queue::dequeue()
{
try
{
if(front>rear)
throw 0;
}
catch(int)
{
cout<<"queue is empty\n";
return 0;
}
return a[rear];
}

void queue::enqueue(int ch)
{
try
{
if(cap==size)
throw size;
}
catch(int)
{
cout<<"queue is full\n";
return;
}
a[++rear]=ch;
size++;
}

void stack::push(int op)
{
try
{
if(top==SIZE)
throw top;
}
catch(int)
{
cout<<"Stack is Full \n";
return;
}
++top;
stck[top]=op;
}
int stack::pop()
{
try
{
int(top==0)
throw 0;
}
catch(int)
{
cout<<"Stack is Empty!\n";
return 0;
}
top--
return stck[top];
}
livesinabox
Newbie Poster
4 posts since May 2010
Reputation Points: 10
Solved Threads: 0
 

yeah, it would work!!!!!


But try using exception hierarchy in future.....it is more elegant, easy for complex problems

dustfingers
Newbie Poster
3 posts since Oct 2010
Reputation Points: 10
Solved Threads: 1
 

>>And in school we used VC++ but I don't have it at home

Why not? The express version is free for the asking (downloading). Would you build an engine for a 50 year-old car and expect it to work on a 2010 model?

Ancient Dragon
Retired & Loving It
Team Colleague
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: