473,746 Members | 2,700 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

STRANGE behaviour when working with exceptions

Hi,

a strange behaviour when working with exceptions :

when I divide and integer by 0 will an exception be thrown. OK
but, when I divide a double by 0 is no exception thrown ???
How come ?

Try it out.

try
{
int i=1, j=0;
int result = i / j;

// double i=1.0, j=0;
// double result = i / j;

Console::WriteL ine("Result {0} / {1} = {2}", i.ToString(), j.ToString(),

result.ToString ());
}
catch (Exception* pExc)
{
Console::WriteL ine("Exception caught : '{0}' ", pExc->Message);
}

can anybody explain this ?

thnx
Chris
Nov 17 '05 #1
1 1135
Chris wrote:
Hi,

a strange behaviour when working with exceptions :

when I divide and integer by 0 will an exception be thrown. OK
but, when I divide a double by 0 is no exception thrown ???
How come ?

Try it out.

try
{
int i=1, j=0;
int result = i / j;

// double i=1.0, j=0;
// double result = i / j;

Console::WriteL ine("Result {0} / {1} = {2}", i.ToString(),
j.ToString(),

result.ToString ());
}
catch (Exception* pExc)
{
Console::WriteL ine("Exception caught : '{0}' ", pExc->Message);
}

can anybody explain this ?


Floating point exceptions are masked by default. When you divide a double
by o you get back positive or negative infinity. The 'int' type has no
value to represent infinity, so there's no sensible default behavior except
to raise an exception.

From native C++ you can enable floating point exceptions using _controlfp().
There does not appear to be any .NET equivalent.

-cd
Nov 17 '05 #2

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

Similar topics

2
1972
by: Paul Drummond | last post by:
Hi all, I am developing software for Linux Redhat9 and I have noticed some very strange behaviour when throwing exceptions within a shared library. All our exceptions are derived from std::exception. We have a base class which all processes derive from which is always instantiated in main surrounded by a try/catch(std::exception) which catches all exceptions that have not be handled at a higher level. The catch block cleans up and...
3
4873
by: Sebastian C. | last post by:
Hello everybody Since I upgraded my Office XP Professional to SP3 I got strange behaviour. Pieces of code which works for 3 years now are suddenly stop to work properly. I have Office XP Developer (SP3 for Office, SP1 for developer, JET40SP8) on Windows XP Home Edition (SP1). The same behaviour occurs on Windows 98 too.
6
2932
by: Edd Dawson | last post by:
Hi. I have a strange problem involving the passing of command line arguments to a C program I'm writing. I tried posting this in comp.programming yesterday but someone kindly suggested that I'd have better luck here. So here goes! My program ignores any command line arguments, or at least it's supposed to. However, when I pass any command line arguments to the program, the behaviour of one of the functions changes mysteriously. I have...
10
2590
by: bear | last post by:
hi all, I have a program whose speed is so strange to me. It is maily used to calculate a output image so from four images s0,s1,s2,s3 where so=(s0-s2)^2+ (s1-s3)^2. I compile it with gcc (no optimization). the codec between /***********/ is the initialization code. What supprise me a lot is the code with initialization(io==1) is much faster than without initialization(io!=1). The initialization code should takes some time and it should...
2
1340
by: Chris | last post by:
Hi, a strange behaviour when working with exceptions : when I divide and integer by 0 will an exception be thrown. OK but, when I divide a double by 0 is no exception thrown ??? How come ? Try it out.
2
1060
by: Alfonso Morra | last post by:
Hi, I have written a simple test harness (exe) for a C++ (native) DLL that exports some C++ objects. The objects throw exceptions when they an error occurs in the Ctor, and the test harness is supposed to catch the exception. I have noticed that when I am debugging the DLL (i.e. using the test harness executable as the app to call the DLL), the exceptions are caught (as expected), in the test harness code. However, when I am
2
1390
by: danil.shopyrin | last post by:
Hello! We have some code that is written in COM. It was used in a "ISAPI-extension server " and everithing was fine. And it is fine at the moment. But now this code is used from the ASP.NET server. And we receive some unknown exceptions. Them occurs after a long period of working (about of 10,000 stress-test-queries). We can't ever recognize these exceptions.
31
2888
by: gamehack | last post by:
Hi all, I've been testing out a small function and surprisingly it does not work okay. Here's the full code listing: #include "stdlib.h" #include "stdio.h" char* escaped_byte_cstr_ref(char byte); int main (int argc, const char * argv)
6
2451
by: Mikus Sleiners | last post by:
Is there any way to enable exception throws in VS 2005, that occur during binding operations? I am upset that i can't see exceptions that are thrown during binding operations. It's very hard to track down erroneous behaviour of your app if you can't see where the problem is... i mean it's realy hard to debug binding issues and it would be realy of help if i could somehow enable this during debug session.
0
8974
marktang
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...
0
8800
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9508
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9350
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9285
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,...
0
8229
agi2029
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...
1
6772
isladogs
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...
1
3292
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
3
2199
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.