Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > poping empty stack in visual c++ express - doesn't throw exception ?

Reply
Thread Tools

poping empty stack in visual c++ express - doesn't throw exception ?

 
 
KRUNOPOPOVIC@YAHOO.COM
Guest
Posts: n/a
 
      03-05-2007
Hello,

This code give me "deque empty before pop" error
with visual c++ express in debug configuration mode.

Why poping empty stack doesn't throw exception ?

Uncommenting the line solves the problem.

Kruno


#include<iostream>
#include<stack>
using namespace std;

int main()
{
stack<int> s ;

try
{
//if (s.empty()) throw "something";
s.pop();
}
catch(...)
{
cout<< "hello empty stack" << endl;
}

return 0;
}

 
Reply With Quote
 
 
 
 
John Harrison
Guest
Posts: n/a
 
      03-05-2007
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> Hello,
>
> This code give me "deque empty before pop" error
> with visual c++ express in debug configuration mode.
>
> Why poping empty stack doesn't throw exception ?
>


Because there is no requirement in C++ do to so.

john
 
Reply With Quote
 
 
 
 
KRUNOPOPOVIC@YAHOO.COM
Guest
Posts: n/a
 
      03-05-2007

John Harrison je napisao/la:
> (E-Mail Removed) wrote:
> > Hello,
> >
> > This code give me "deque empty before pop" error
> > with visual c++ express in debug configuration mode.
> >
> > Why poping empty stack doesn't throw exception ?
> >

>
> Because there is no requirement in C++ do to so.
>
> john


Thank you John,

means it is proprietary MS solution,
and other c++ compiler vendors doesn't have to follow that?

kruno

 
Reply With Quote
 
John Harrison
Guest
Posts: n/a
 
      03-05-2007
(E-Mail Removed) wrote:
> John Harrison je napisao/la:
>
>>(E-Mail Removed) wrote:
>>
>>>Hello,
>>>
>>>This code give me "deque empty before pop" error
>>>with visual c++ express in debug configuration mode.
>>>
>>>Why poping empty stack doesn't throw exception ?
>>>

>>
>>Because there is no requirement in C++ do to so.
>>
>>john

>
>
> Thank you John,
>
> means it is proprietary MS solution,
> and other c++ compiler vendors doesn't have to follow that?
>
> kruno
>


That's right, popping an empty stack is undefined behaviour and
different vendors can do whatever they think is best.

john
 
Reply With Quote
 
KRUNOPOPOVIC@YAHOO.COM
Guest
Posts: n/a
 
      03-05-2007
John,

Where can I get more information such as "popping an empty stack is
undefined behaviour" ?
Can I use Stroustrup for that ?

Kruno



John Harrison je napisao/la:
> (E-Mail Removed) wrote:
> > John Harrison je napisao/la:
> >
> >>(E-Mail Removed) wrote:
> >>
> >>>Hello,
> >>>
> >>>This code give me "deque empty before pop" error
> >>>with visual c++ express in debug configuration mode.
> >>>
> >>>Why poping empty stack doesn't throw exception ?
> >>>
> >>
> >>Because there is no requirement in C++ do to so.
> >>
> >>john

> >
> >
> > Thank you John,
> >
> > means it is proprietary MS solution,
> > and other c++ compiler vendors doesn't have to follow that?
> >
> > kruno
> >

>
> That's right, popping an empty stack is undefined behaviour and
> different vendors can do whatever they think is best.
>
> john


 
Reply With Quote
 
John Harrison
Guest
Posts: n/a
 
      03-05-2007
(E-Mail Removed) wrote:
> John,
>
> Where can I get more information such as "popping an empty stack is
> undefined behaviour" ?
> Can I use Stroustrup for that ?
>
> Kruno
>


Don't know, sorry.
 
Reply With Quote
 
KRUNOPOPOVIC@YAHOO.COM
Guest
Posts: n/a
 
      03-05-2007
John,

To be precise, where can I find more about situations always throwing
exception in c++ ?
How did your answer me about stack - from experience or some book ?

Thank you very much,
Kruno


John Harrison je napisao/la:
> (E-Mail Removed) wrote:
> > John,
> >
> > Where can I get more information such as "popping an empty stack is
> > undefined behaviour" ?
> > Can I use Stroustrup for that ?
> >
> > Kruno
> >

>
> Don't know, sorry.


 
Reply With Quote
 
John Harrison
Guest
Posts: n/a
 
      03-05-2007
(E-Mail Removed) wrote:
> John,
>
> To be precise, where can I find more about situations always throwing
> exception in c++ ?
> How did your answer me about stack - from experience or some book ?
>
> Thank you very much,
> Kruno
>


From experience. There are almost no exceptions required to be thrown
by the standard C++ library. vector::at throws an exception, several of
the string methods throw exceptions, new can throw an exception, but
that is just about all.

Doing almost any bad thing (like popping an empty stack) is undefined
behaviour.

john
 
Reply With Quote
 
Kai-Uwe Bux
Guest
Posts: n/a
 
      03-05-2007
(E-Mail Removed) wrote:

> John,
>
> Where can I get more information such as "popping an empty stack is
> undefined behaviour" ?
> Can I use Stroustrup for that ?


The C++ standard is the ultimate reference for this kind of information. It
does not teach you how to program, but it defines the language and terms
like "undefined behavior".


> John Harrison je napisao/la:
>> (E-Mail Removed) wrote:
>> > John Harrison je napisao/la:
>> >

[snip]

And, please don't top post.


Best

Kai-Uwe Bux
 
Reply With Quote
 
KRUNOPOPOVIC@YAHOO.COM
Guest
Posts: n/a
 
      03-05-2007
Very nice answer John,
have a good day

Kruno

John Harrison je napisao/la:
> (E-Mail Removed) wrote:
> > John,
> >
> > To be precise, where can I find more about situations always throwing
> > exception in c++ ?
> > How did your answer me about stack - from experience or some book ?
> >
> > Thank you very much,
> > Kruno
> >

>
> From experience. There are almost no exceptions required to be thrown
> by the standard C++ library. vector::at throws an exception, several of
> the string methods throw exceptions, new can throw an exception, but
> that is just about all.
>
> Doing almost any bad thing (like popping an empty stack) is undefined
> behaviour.
>
> john


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Why does std::stack::pop() not throw an exception if the stack is empty? Debajit Adhikary C++ 36 02-10-2011 08:54 PM
C/C++ compilers have one stack for local variables and return addresses and then another stack for array allocations on the stack. Casey Hawthorne C Programming 3 11-01-2009 08:23 PM
To throw or to throw not? Emanuele D'Arrigo Python 6 11-15-2008 04:12 PM
JNI's throw new does not throw an exception yarona@m-sys.com Java 15 09-08-2005 08:36 AM
Throw Exception Vs Throw New Exception Kerri ASP .Net 2 10-27-2003 02:13 PM



Advertisments