473,406 Members | 2,619 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,406 software developers and data experts.

About system.overflowexception

I got a CER from a client said that a system.overflowexception thrown
when executing the following stentence:
Vertor3 v = p1 - p2;
Here the p1, p2 are variables of self defined struct --- Point3,
Vector3 is also a self defined struct type, they are definitions as
below:
struct Point3 struct
Vector3
{ {
float x, y, z;
float x, y, z;
} }

Point3 overode its -operation:
struct Point3
{
public static Vector3 operator - (Point3 p1, Point3 p2)
{
return new Vector3(p1.x-p2.x, p1.y - p2.y, p1.z - p2.z);
}
}

As I know that the arithmetic between the float type never throw
system.overflowexception.
So, the exception only can be thrown when create a Vector3.
Vector3 has three type constructs:
1. public Vector3(float x, float y, float z)
2. public Vector3(double x, double y, double z)
3. public Vector3(int x, int y, int z)
That means during runtime the construct --- Vector3(int x, int y, int
z) was invoked which eventually caused this exception.
Does anyone could help me to explain how could this case happen? or
there are some errors in my analysis?

Thanks,

Steven

Nov 1 '07 #1
4 3428
That means during runtime the construct --- Vector3(int x, int y, int z) was invoked

What makes you think this? Can you post the ctor code at all? float-
float=float, so your line Vector3(p1.x-p2.x, p1.y - p2.y, p1.z -
p2.z) should invoke Vector3(float,float,float). Eitherway, float will
do an implicit cast to double, but not to int - so it won't be using
the int ctor unless you are twisting its arm.

I think the devil may be in the detail here... can you post the actual
code for Point3 and Vector3 at all? In particular the - operator, the
constructor, and the field/property members for x,y,z

Marc

Nov 1 '07 #2

Thank you Marc and I so impressed for the quick reply.
The Vector3's constructors as following:
public struct Vector3
{
float _x, _y, _z;
public Vector3(int x, int y, int z)
{
_x = x;
_y = y;
_z = z;
}

public Vector3(float x, float y, float z)
{
_x = x;
_y = y;
_z = z;
}

public Vector3(double x, double y, double z)
{
_x = (float)x;
_y = (float)y;
_z = (float)z;
}
}

I thought that the system.overflowexception only could be thrown by an
integer type, so I guessed the constructor Vector3(int x, int y, int
z) being called.

The -operation of the Point3 just exactly as I wrote.
For the whole actual code, because I am in home now, you know, I can
not recall it nicely.

Thank you for your reply again.

Steven




}
Nov 1 '07 #3
Hi,

Did you try to debug it? and go into the methods?

Also a short but a complete example will help as we could run it and try
ourselves.

--
Ignacio Machin
http://www.laceupsolutions.com
Mobile & warehouse Solutions.
<st**************@126.comwrote in message
news:11**********************@e34g2000pro.googlegr oups.com...
>I got a CER from a client said that a system.overflowexception thrown
when executing the following stentence:
Vertor3 v = p1 - p2;
Here the p1, p2 are variables of self defined struct --- Point3,
Vector3 is also a self defined struct type, they are definitions as
below:
struct Point3 struct
Vector3
{ {
float x, y, z;
float x, y, z;
} }

Point3 overode its -operation:
struct Point3
{
public static Vector3 operator - (Point3 p1, Point3 p2)
{
return new Vector3(p1.x-p2.x, p1.y - p2.y, p1.z - p2.z);
}
}

As I know that the arithmetic between the float type never throw
system.overflowexception.
So, the exception only can be thrown when create a Vector3.
Vector3 has three type constructs:
1. public Vector3(float x, float y, float z)
2. public Vector3(double x, double y, double z)
3. public Vector3(int x, int y, int z)
That means during runtime the construct --- Vector3(int x, int y, int
z) was invoked which eventually caused this exception.
Does anyone could help me to explain how could this case happen? or
there are some errors in my analysis?

Thanks,

Steven

Nov 1 '07 #4
And Point3? again, in particular the properties/fields... I can't seee
anything obvious; are you sure about where it blows up?

Marc

Nov 1 '07 #5

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

Similar topics

54
by: Brandon J. Van Every | last post by:
I'm realizing I didn't frame my question well. What's ***TOTALLY COMPELLING*** about Ruby over Python? What makes you jump up in your chair and scream "Wow! Ruby has *that*? That is SO...
125
by: Sarah Tanembaum | last post by:
Beside its an opensource and supported by community, what's the fundamental differences between PostgreSQL and those high-price commercial database (and some are bloated such as Oracle) from...
3
by: CSharpX | last post by:
I have the following code and when the exception is raised the OS displays a nasty Stop dialog box it says an unhandled exception occured, gives 3 buttons to click details, contintue Quit... i do...
2
by: Amin Sobati | last post by:
Hi, I have the following code in my app: Dim intx As Integer Dim inty As Integer Dim intz As Integer inty = 0 intx = 5 Try intz = intx / inty
5
by: Andrea | last post by:
....without changing the data type. I have been working on this for over 5 hours, please help me so I don't have to shoot myself. It's due by midnight... Here's my code: (Variables are declared...
5
by: Patrick Dickey | last post by:
Hello, All! I'm modifying some source code that I downloaded from Planet-source-code a while back, and have a question about Try Catch statements. Basically, I'm wondering if I can do a Try with...
4
by: Nathan Sokalski | last post by:
During my postbacks, I try to assign the value from an Input tag to a property of a custom control. However, I keep recieving the following error: An exception of type...
0
by: stevencheng_2007 | last post by:
I got a CER from a client said that a system.overflowexception thrown when executing the following stentence: Vertor3 v = p1 - p2; Here the p1, p2 are variables of self defined struct --- Point3,...
7
by: =?Utf-8?B?RWR3YXJk?= | last post by:
Hi everybody, I was testing a piece of code and I noticed that try catch block doesn't recognize "DivideByZeroException" when I have zero in denominator and I have to use the "OverflowException" ,...
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.