473,385 Members | 1,863 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,385 software developers and data experts.

throw wth no operand

Ben
I have been experiencing which I've managed to simplify down to the
following code. Is my assertion in the code misplaced? My compiler
(MSVC++ 6) hits the assert when I believe it should just abort after
the second throw.

#include <windows.h>
#include <assert.h>

void anotherFunction()
{
int *p = 0;
if(!p)
throw 1;

assert(false); // shouldn't get here, should we?
}

int main()
{
try
{
anotherFunction();
}
catch(int)
{
throw;
}
return 0;
}

Regards
Ben
Jul 22 '05 #1
2 1737

Ben skrev i meldingen ...
I have been experiencing which I've managed to simplify down to the
following code. Is my assertion in the code misplaced? My compiler
(MSVC++ 6) hits the assert when I believe it should just abort after
the second throw.
MSVC 6 has a number of bugs relating to exception handling, especially
rethrowing (e.g. an exception's destructor might be called twice).
#include <windows.h>
#include <assert.h>

void anotherFunction()
{
int *p = 0;
if(!p)
throw 1;

assert(false); // shouldn't get here, should we?
}

int main()
{
try
{
anotherFunction();
}
catch(int)
{
throw;
}
return 0;
}


Are you sure you're hitting the assert and not just invoking the general
top-level handler supplied by the compiler?

Try some flushed output.

It might be that you need to catch that exception as unsigned int -- but
instead, use std::runtime_error.

Jul 22 '05 #2
Ben
> Are you sure you're hitting the assert and not just invoking the general
top-level handler supplied by the compiler?
Yes, definitely hitting the assert.
It might be that you need to catch that exception as unsigned int -- but
instead, use std::runtime_error.


Catching it as unsigned int caused an unhandled exception (not
surprisingly I has to chang the "throw 1;" to "throw 1u;" to make it
work again).

Interestingly, if I rethrow the exception in main using

catch(int i)
{
throw i;
}

....it causes an unhandled exception (fair enough) and then generates
the error about "not saving the value of ESP across function calls".
This suggests to me that the compiler has generated incorrect assembly
code. Any thoughts on that?

If I handle it in main like this

catch(int i)
{
throw;
}

....the throw exectution to immediately jump back to the line after the
original "throw 1;" statement. Which you'll see (from my original
post) is the "assert(false);" statement.

Confused
Ben
Jul 22 '05 #3

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

Similar topics

6
by: DJ Craig | last post by:
I keep getting this error: Fatal error: Unsupported operand types in /usr/local/etc/httpd/htdocs/djtricities/kat/bpmchart/chart.php on line 58 I've looked for hours for some type of error, and...
2
by: Tim Mierzejewski | last post by:
You guys were so great with answering my first question that I've decided to ask you yet again! Again, only the relevant code is included. typedef unsigned int unint; #include <iostream> ...
2
by: Kostatus | last post by:
The following code worked perfectly fine until i modified an unrelated part of the program: this->dungArea.mBlocked = mioS.mio_dungArea.mFlags & isBlocked; after that i started getting the...
6
by: BlueTrin | last post by:
Hello I was adapting a C version of SolvOpt in C++ to use it within a virtual class. However I am stuck with the overriding of evaluation and gradiant functions. cStepCurveEvaluator.cpp...
1
by: programmingChick | last post by:
I have a program where I want to accept an operand (from a file) and apply that operand to some integers. How should I do that? Is the best way to convert it to its ascii character then figure out...
19
by: Rajesh S R | last post by:
Consider the following code: int main() { struct name { long a; int b; long c; }s={3,4,5},*p; p=&s;
5
by: stevewilliams2004 | last post by:
I was wondering if someone could explain the output I am getting for the program below. What I expected from the main program output was "Cat" but instead I see "Mammal". The output is also...
7
by: somenath | last post by:
Hi All, I am trying to undestand "Type Conversions" from K&R book.I am not able to understand the bellow mentioned text "Conversion rules are more complicated when unsigned operands are...
18
by: Ranganath | last post by:
Why is throw keyword considered as an operator?
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.