473,320 Members | 1,945 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

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

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<ints ;

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

return 0;
}

Mar 5 '07 #1
11 6304
KR**********@YAHOO.COM 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
Mar 5 '07 #2

John Harrison je napisao/la:
KR**********@YAHOO.COM 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 '07 #3
KR**********@YAHOO.COM wrote:
John Harrison je napisao/la:
>>KR**********@YAHOO.COM 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 '07 #4
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:
KR**********@YAHOO.COM wrote:
John Harrison je napisao/la:
>KR**********@YAHOO.COM 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 '07 #5
KR**********@YAHOO.COM 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 '07 #6
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:
KR**********@YAHOO.COM 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 '07 #7
KR**********@YAHOO.COM 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 '07 #8
Very nice answer John,
have a good day

Kruno

John Harrison je napisao/la:
KR**********@YAHOO.COM 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 '07 #9
KR**********@YAHOO.COM 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:
>KR**********@YAHOO.COM wrote:
John Harrison je napisao/la:
[snip]

And, please don't top post.
Best

Kai-Uwe Bux
Mar 5 '07 #10
John Harrison wrote:
KR**********@YAHOO.COM 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
Mar 5 '07 #11
KR**********@YAHOO.COM 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>
Mar 5 '07 #12

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Robert A. van Ginkel | last post by:
Hello Fellow Developer, This looks like a long mail, but at the end of this post is my socket wrapper attached. I want to make a timeout procedure that starts counting down after the...
7
by: Andy Fish | last post by:
Hi, in my c# code I have something like this: try { ... } catch (Exception ex) { ... throw ex; }
5
by: Senthilvel | last post by:
Hi, The automatic variables declared in the try bock will be destroyed when an exception is thrown due to stack unwinding. So i expected the following code to call the destructor of B but it...
13
by: Ben R. Bolton | last post by:
The documentation indicates that the threads "default stack size" is 1MB. The work "default" implies that it can be changed. Is it possible to change the StackSize in .NET? If so how? Is it...
0
by: Mike Schilling | last post by:
I have some code that calls methods reflectively (the method called and its parameters are determined by text received in a SOAP message, and I construct a map from strings to MethodInfos). The...
0
by: cronman | last post by:
I am creating a small Windows application using Visual C# 2005 Express Edition (August CTP) for a small non-profit agency. My current issue is with updating related information in an Access...
2
by: Lasse Vågsæther Karlsen | last post by:
If I got the following code: try { // something that might throw an exception } catch (Exception ex) { // Log contents of ex here throw;
4
by: Satya | last post by:
I am trying to display a PDF file (which I am being passed from a web service as a binary stream) in a browser, but I am being prompted to save the file instead. I don't want the user to be...
9
by: John Devlon | last post by:
Hi, I would like to check if a text field is empty; I'm using this code ... Dim strTitle As String = String.Empty Try strTitle = Trim(txtTitle.Text) Catch ex As Exception When strTitle =...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.