I have a class with the following public function:
float FuncClass::GetR esult() {
try {
return(Result);
} catch (...) {
WriteString("Fu ncClass::GetRes ult ERROR: Exception encountered");
return(0);
}
}
Result is a private variable of type float. I am repeatedly seeing the
catch portion being executed from the above code, and my Borland debugger is
telling me that it is an EOverflow exception.
How is it possible that such an exception is triggered by a return
statement. It would seem logical that if an overflow situation occurrs, it
would happen when I am assigning (an addition) to the Result variable, but
not when I am returning the Result variable. How is this possible? 7 3128
Victor Hannak wrote: I have a class with the following public function:
float FuncClass::GetR esult() { try { return(Result); } catch (...) { WriteString("Fu ncClass::GetRes ult ERROR: Exception encountered"); return(0); } }
Result is a private variable of type float. I am repeatedly seeing the catch portion being executed from the above code, and my Borland debugger is telling me that it is an EOverflow exception.
How is it possible that such an exception is triggered by a return statement. It would seem logical that if an overflow situation occurrs, it would happen when I am assigning (an addition) to the Result variable, but not when I am returning the Result variable. How is this possible?
First of all I guess this is not a standard mandated behavior. The second
(guess, since you did not post the code, only a fragment) is that you return
a double as a flot - and it just does not fit.
Attila
Actually, Result _is_ of type float. That was the first thing I thought of.
I'm not sure how much more code I need to post, after all, the segment I
included is the portion that's causing the exception. I would think that no
matter what my program does (to the result variable) before this code is
called should be irrelevant.
Anyone have any suggestion on what I could do to try to figure out what's
going on?
Vic First of all I guess this is not a standard mandated behavior. The second (guess, since you did not post the code, only a fragment) is that you
return a double as a flot - and it just does not fit.
Victor,
My answer may seem harsh to you, but please bear in mind that my aim is
to provide you with some guidelines for effectively getting meaningful
help from this group.
Top-posting fixed. Please don't top-post on usenet. Look at this: http://www.parashift.com/c++-faq-lit...t.html#faq-5.4
Victor Hannak wrote: Atilla wrote:
<snip> since you did not post the code, only a fragment)<snip> I'm not sure how much more code I need to post, after all, the segment I included is the portion that's causing the exception.
What ever you post, it should be compilable. That means that we should
be able to cut and paste exactly what you've posted and compile it and
see the same problem you're seeing. This will require some effort on
your part, as you will have to isolate the problem. The upside is that
this is often enough to figure out what the problem is without waiting
for a response on usenet.
I would think that no matter what my program does (to the result variable) before this code is called should be irrelevant. <snip>
This is almost certainly not true. I've added a minimal amount of code
required to turn your fragment into a compilable unit (see below), and
no exception is thrown. That seems to indicate that the problem is not
in the fragment you posted.
-----------------
#include <iostream>
class FuncClass
{
public:
FuncClass(float r) : Result(r) {}
float GetResult();
private:
void WriteString(con st char* s)
{
std::cerr << s << '\n';
}
float Result;
};
float FuncClass::GetR esult() {
try {
return(Result);
} catch (...) {
WriteString("Fu ncClass::GetRes ult ERROR: Exception encountered");
return(0);
}
}
int
main()
{
FuncClass fc(1.0);
std::cout << fc.GetResult() << '\n';
return 0;
}
-----------------
- Adam
I have been unable to isolate _or_ reproduce the problem in a simple
testcase. That is why I posted to the group in the first place... I was
hoping for a response from someone saying something like: "I had that same
problem before when I didn't initialize the class public variable I was
returning". What ever you post, it should be compilable. That means that we should be able to cut and paste exactly what you've posted and compile it and see the same problem you're seeing. This will require some effort on your part, as you will have to isolate the problem. The upside is that this is often enough to figure out what the problem is without waiting for a response on usenet.
I think you've missed my point here. I completely agree that the problem is
not with the posted fragment (otherwise, I could generate a testcase). The
question is what could I possibly be doing wrong prior to the return that
would cause an exception when the return is called, while not causing an
exception prior to the return. I would think that no matter what my program does (to the result variable) before this code is called should be irrelevant. <snip>
This is almost certainly not true. I've added a minimal amount of code required to turn your fragment into a compilable unit (see below), and no exception is thrown. That seems to indicate that the problem is not in the fragment you posted.
Top posting fixed...my apologies...
"Victor Hannak" <victor.hannak@ no****@rocheste r.rr.com> wrote in message
news:p3******** *********@twist er.nyroc.rr.com ... What ever you post, it should be compilable. That means that we should be able to cut and paste exactly what you've posted and compile it and see the same problem you're seeing. This will require some effort on your part, as you will have to isolate the problem. The upside is that this is often enough to figure out what the problem is without waiting for a response on usenet. I have been unable to isolate _or_ reproduce the problem in a simple testcase. That is why I posted to the group in the first place... I was hoping for a response from someone saying something like: "I had that same problem before when I didn't initialize the class public variable I was returning".
I would think that no matter what my program does (to the result variable) before this code
is called should be irrelevant. <snip>
This is almost certainly not true. I've added a minimal amount of code required to turn your fragment into a compilable unit (see below), and no exception is thrown. That seems to indicate that the problem is not in the fragment you posted.
I think you've missed my point here. I completely agree that the problem
is not with the posted fragment (otherwise, I could generate a testcase).
The question is what could I possibly be doing wrong prior to the return that would cause an exception when the return is called, while not causing an exception prior to the return.
Victor Hannak wrote: Top posting fixed...my apologies...
Victor, I have only few suggestions to you (since I have never used a system
where such overflow exception was present).
RTFM. Take your manual and read when does such overflow exception occur.
This - even if it will not give you the ahaaaa effect and make you
immediately find the problem - will at least help you on knowing what are
you looking for.
If the previous step did not help to find the error fire up the debugger and
stop your code right before it would run that very return statement.
Examine the programs state and look for such things, which can cause the
overflow (as you have learnt about all of them by reading the manual).
As these overflow (as far as I know) are not standardized for C++ (I might
be very wrong about it) you will need to see your docs (compiler or CPU) to
figure out what can cause such an overflow.
As a last guess it might also be possible that it is not the return
statement itself, but you are trying to put the returned number into a type
(variable?) where it does not fit. But of course it is just a guess, since
I do not know when can such exception occur. But (for example) if the
return value gets converted to int (or something else which might overflow)
you will probably see this as if the return statement itself did throw...
--
WW aka Attila
Victor Hannak wrote: Top posting fixed...my apologies...
Um... You are top-posting to tell us that you won't top-post anymore?
....
-Kevin
--
My email address is valid, but changes periodically.
To contact me please use the address from a recent posting. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Aguilar, James |
last post by:
Hello all,
To begin, yes, this -is- a homework assignment. However, it is for my
Algorithms class, and my instructor has given us explicit permission to use
"expert" groups like newsgroups, so if that's your only reason not to help,
please do. Otherwise, I guess it's OK. But, just remember, I'm not asking
you to do my work for me, just to point out my error.
My problem is not with the algorithm itself (standard divide and conquer on...
|
by: JKop |
last post by:
You know how the saying goes that *unsigned* overflow is...
well.. defined. That means that if you add 1 to its maximum
value, then you know exactly what value it will have
afterward on all implementations.
But then you have signed integers. Let's say a signed
integer is set to its maximum positive value. If you add 1
to it, what happens?:
A) It's implementation defined what value it will
|
by: Chua Wen Ching |
last post by:
Thanks Derek...
Okay i had another question..
my program runs smoothly for the first minute, after 1
minute...
suddenly it breaks and display this error:
do you know what is the cause of this problem...
|
by: Gorge Bush |
last post by:
Hi there,
all was going well with my first C# project until now as I am
getting a Stack Overflow exception. I haven't seen one of those since DOS
programming days and back then all you did was up the stack size. How do I
get around this in .Net?
|
by: junky_fellow |
last post by:
Is there any way by which the overflow during addition of two integers
may
be detected ?
eg.
suppose we have three unsigned integers, a ,b, c.
we are doing a check like
if ((a +b) > c)
do something;
| |
by: linq936 |
last post by:
I have some algorithm dealing with unsigned int calculation a lot, I am
trying to add some check for overflow. The initial thinking was very
easy, just do something like this,
int addition(unsigned int i1, unsigned int i2) {
if ( i1 + i2 < i1 || i1 + i2 < i2 ) {
...throw some expception...
}
return i1+i2;
}
|
by: Mike |
last post by:
Hello All,
Please, if anyone can point me to the problem, I'd sure appreciate it!
I am very new to VB programming and not a programmer to begin with.
This is part of a Visual Basic 2005 Express Edition program to control a remote basketball
scoreboard display unit.
All I'm trying to do is add 5 byte variables and store the result in an integer
variable. I added a Try/Catch block to take look at things.
This exception occurs only when...
|
by: Angel Tsankov |
last post by:
Hello!
Does the C++ standard define what happens when the size argument of void*
operator new(size_t size) cannot represent the total number of bytes to be
allocated? For example:
struct S
{
char a;
};
|
by: thomas.mertes |
last post by:
Is it possible to use some C or compiler extension to catch
integer overflow?
The situation is as follows:
I use C as target language for compiled Seed7 programs.
For integer computions the C type 'long' is used.
That way native C speed can be reached.
Now I want to experiment with raising a Seed7 exception
(which is emulated with setjmp(), longjmp() in C) for integer
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
| |
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |