Hi Friends,
I am trying following code
int main(void)
{
try
{
int i,j,k;
i=10;
j=0;
k= i/j;
}
catch(...)
{
printf("Erro!~");
return 1;
}
return 0;
}
Here it's divide by Zero error.
Now using MSVC compiler. the code flow lands up in catch block.
but gcc comiler the code simply throws "floating point exception"
can terminates.
Any comments?? 5 7567
Neo wrote:
Hi Friends,
I am trying following code
int main(void)
{
try
{
int i,j,k;
i=10;
j=0;
k= i/j;
}
catch(...)
{
printf("Erro!~");
return 1;
}
return 0;
}
Here it's divide by Zero error.
Now using MSVC compiler. the code flow lands up in catch block.
but gcc comiler the code simply throws "floating point exception"
can terminates.
Any comments??
The behavior on a division by zero is undefined. So anything can happen. The
exception that gcc mentions is not a C++ exception, but rather a CPU
exception.
Rolf Magnus wrote:
Neo wrote:
Hi Friends,
I am trying following code
int main(void)
{
try
{
int i,j,k;
i=10;
j=0;
k= i/j;
}
catch(...)
{
printf("Erro!~");
return 1;
}
return 0;
}
Here it's divide by Zero error.
Now using MSVC compiler. the code flow lands up in catch block.
but gcc comiler the code simply throws "floating point exception"
can terminates.
Any comments??
The behavior on a division by zero is undefined. So anything can happen. The
exception that gcc mentions is not a C++ exception, but rather a CPU
exception.
What you are saying is true. So If I want to write an application which
should be capable ot resuming the execution. What I need to do ? I am
targeting windows,Redhat and solaris platforms.
Neo wrote:
Rolf Magnus wrote:
Neo wrote:
Hi Friends,
I am trying following code
>
int main(void)
{
try
{
int i,j,k;
i=10;
j=0;
>
k= i/j;
}
catch(...)
{
printf("Erro!~");
return 1;
}
return 0;
}
>
Here it's divide by Zero error.
>
Now using MSVC compiler. the code flow lands up in catch block.
>
but gcc comiler the code simply throws "floating point exception"
can terminates.
>
Any comments??
The behavior on a division by zero is undefined. So anything can happen. The
exception that gcc mentions is not a C++ exception, but rather a CPU
exception.
What you are saying is true. So If I want to write an application which
should be capable ot resuming the execution. What I need to do ? I am
targeting windows,Redhat and solaris platforms.
Check if they are zero before doing the division and throw your own
exception.
Note that if you divide doubles it will not throw an exception if the
divisor is 0.0 but will return a NaN type. (Infinity or Negative
Infinity).
Neo wrote:
>
Rolf Magnus wrote:
>Neo wrote:
Hi Friends,
I am trying following code
int main(void)
{
try
{
int i,j,k;
i=10;
j=0;
k= i/j;
}
catch(...)
{
printf("Erro!~");
return 1;
}
return 0;
}
Here it's divide by Zero error.
Now using MSVC compiler. the code flow lands up in catch block.
but gcc comiler the code simply throws "floating point exception"
can terminates.
Any comments??
The behavior on a division by zero is undefined. So anything can happen. The exception that gcc mentions is not a C++ exception, but rather a CPU exception.
What you are saying is true. So If I want to write an application which
should be capable ot resuming the execution. What I need to do ? I am
targeting windows,Redhat and solaris platforms.
Maybe just use an if-statement to test if 'j' is 0? You can recover in the
if-statement or throw an exception and recover in the catch-block?
alvin
Neo wrote:
Hi Friends,
I am trying following code
int main(void)
{
try
{
int i,j,k;
i=10;
j=0;
k= i/j;
}
catch(...)
{
printf("Erro!~");
return 1;
}
return 0;
}
Here it's divide by Zero error.
Now using MSVC compiler. the code flow lands up in catch block.
but gcc comiler the code simply throws "floating point exception"
can terminates.
Any comments??
MSVC is fooling you a little bit. It does not throw C++
exceptions, but rather "structured exceptions". Only because
you're using the ellipsis (...) form of catch are you getting
the exception.
Linux and UNIX like systems use "signals" to indicate problems.
You need to create a signal handler. Modern versions of the
gcc compiler allow you to throw an exception from the signal
handler.
/Glen Dayton This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Ryan |
last post by:
I have the following line in a select statement which comes up with a
divide by zero error.
CAST(CASE Splinter_Status
WHEN 'SUR' THEN 0
ELSE CASE WHEN Sacrifice>=1
THEN...
|
by: Mike Leahy |
last post by:
All...
I have a query that calculates various using variables from a survey
database. As with any survey, there are many instantces of null values. I'm
wondering if there is any way to escape...
|
by: Gary Carson |
last post by:
Can anyone tell why the query below would throw a divide-by-zero
error? The only reason I can see for the error happening would be if
SUM() came out to be zero, but this never happens with the...
|
by: Joriveek |
last post by:
When I specify a formula between Computed Column Specification, I have two
zero values, getting Divide by Zero error, any idea how can I avoid this? I
still want SQL Server to display Zero if it is...
|
by: shuisheng |
last post by:
Dear all,
Assume I have two big arrays A and B. And I want to element-wise divide
A by B. When an element of B is zero, the results are also zero.
Such as A = { 2, 4, 0, 6}
B = { 1, 0, 0, 2}...
|
by: =?Utf-8?B?bWljaGFlbGd3ZWllcg==?= |
last post by:
Hello! I was working on some code the other day, and I came across an odd
discrepancy between the decimal and the double type.
If I attempt to divide a decimal by zero, the framework throws an...
|
by: ollyb303 |
last post by:
Hi,
I have created a report in my Access db which has two columns - I'll call them Number1 and Number2. I have added a textbox to calculate a percentage from these two numbers
=(/) with the...
|
by: zufie |
last post by:
Help!
How do I divide by zero on my form (in a text box).
That is, how do I carry out a division problem when the denominator is
zero?
Thanks!,
John
|
by: Ajay Indian |
last post by:
printf("Divide by zero=%d",1/0);
is giving output 1
while
x=0,y=1;
printf("Divide by zero=%d",y/x);
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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
|
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...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
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...
|
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,...
|
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...
|
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: 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...
| |