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

Discussion in 'C++' started by KRUNOPOPOVIC@YAHOO.COM, Mar 5, 2007.

  1. Guest

    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;
    }
     
    , Mar 5, 2007
    #1
    1. Advertising

  2. Re: poping empty stack in visual c++ express - doesn't throw exception?

    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
     
    John Harrison, Mar 5, 2007
    #2
    1. Advertising

  3. Guest

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

    John Harrison je napisao/la:
    > 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
     
    , Mar 5, 2007
    #3
  4. Re: poping empty stack in visual c++ express - doesn't throw exception?

    wrote:
    > John Harrison je napisao/la:
    >
    >> 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
     
    John Harrison, Mar 5, 2007
    #4
  5. Guest

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

    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:
    > wrote:
    > > John Harrison je napisao/la:
    > >
    > >> 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
     
    , Mar 5, 2007
    #5
  6. Re: poping empty stack in visual c++ express - doesn't throw exception?

    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.
     
    John Harrison, Mar 5, 2007
    #6
  7. Guest

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

    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:
    > 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.
     
    , Mar 5, 2007
    #7
  8. Re: poping empty stack in visual c++ express - doesn't throw exception?

    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
     
    John Harrison, Mar 5, 2007
    #8
  9. Kai-Uwe Bux Guest

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

    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:
    >> wrote:
    >> > John Harrison je napisao/la:
    >> >

    [snip]

    And, please don't top post.


    Best

    Kai-Uwe Bux
     
    Kai-Uwe Bux, Mar 5, 2007
    #9
  10. Guest

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

    Very nice answer John,
    have a good day

    Kruno

    John Harrison je napisao/la:
    > 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
     
    , Mar 5, 2007
    #10
  11. Kai-Uwe Bux Guest

    John Harrison wrote:

    > 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.


    To be more precise, there is a requirement not to throw:

    [23.1/10]: no erase(), pop_back() or pop_front() function throws an
    exception.

    [23.2.3.3/1] defines pop() as equivalent to:

    void pop() { c.pop_back(); }


    Best

    Kai-Uwe Bux
     
    Kai-Uwe Bux, Mar 5, 2007
    #11
  12. Default User Guest

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

    wrote:

    > Very nice answer John,


    Please don't top-post. Your replies belong following or interspersed
    with properly trimmed quotes. See the majority of other posts in the
    newsgroup, or the group FAQ list:
    <http://www.parashift.com/c++-faq-lite/how-to-post.html>
     
    Default User, Mar 5, 2007
    #12
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Kerri
    Replies:
    2
    Views:
    13,035
    Kevin Spencer
    Oct 27, 2003
  2. Buz Waitz

    popup not poping

    Buz Waitz, Jun 15, 2004, in forum: ASP .Net
    Replies:
    5
    Views:
    420
    Buz Waitz
    Jun 16, 2004
  3. Replies:
    15
    Views:
    7,573
    Roedy Green
    Sep 8, 2005
  4. Debajit Adhikary
    Replies:
    36
    Views:
    2,311
    Andre Kaufmann
    Feb 10, 2011
  5. Jake Henderson

    Visual Web Developer 2005 Express and SQL 2005 Express

    Jake Henderson, Mar 10, 2006, in forum: ASP .Net Web Services
    Replies:
    0
    Views:
    237
    Jake Henderson
    Mar 10, 2006
Loading...

Share This Page