Solved

C++ Builder: How to capture Float Overflow signal without pop-up error box

Posted on 2001-08-09
10
706 Views
Last Modified: 2012-06-21
I have a dayend batch program, and do computation.
Currently, there may be some overflow results, and
it pops up "Overflow" box from called functions.
For example, cosh overflow, and program waits for
human confirm.
How can I use  try..__except or other methods to
capture the signal by error handler which I can
assign a default value and do some error handling
steps ?
: ) (asap)
0
Comment
Question by:aavictor
  • 4
  • 3
  • 2
  • +1
10 Comments
 
LVL 2

Expert Comment

by:LoungeLizard
ID: 6371076
have you tried:

try
{
 //code here
}
catch(...)
{
//error handeling here
}

which will catch ALL errors? Then analyze the error, if it is a overflow, do something else throw the execption again for the system to catch
0
 
LVL 2

Expert Comment

by:LoungeLizard
ID: 6371111
or something like:

try
{
//code here
}
catch(Exception &Ex)
{
   if(Ex.ClassName() == "Eoverflow")
   {
       //do something
   }
   else
    throw Ex;
}

This is written of the top of my head, so just double-check!
0
 
LVL 4

Author Comment

by:aavictor
ID: 6371442
How to use Exception
because I get "catch statement missing )." during compilation
=========================== Example of test
#pragma hdrstop
#include <condefs.h>


//---------------------------------------------------------------------------
#pragma argsused
int main(int argc, char **argv)
{
    double i, p;
    int inp;
    i = 1; p = 0.0;

    try {
        i= i/p;
        throw("EZeroDivide");
    }
    catch (const Exception &Ex)
    {
        if(Ex.ClassName() == "Eoverflow")
        {
            puts ("Overflow");
            scanf ("%d", &inp);
        }

    }
        return 0;
}
 
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
LVL 4

Expert Comment

by:IainHere
ID: 6371878
Actually, I don't think an overflow is a C++ exception, so it won't be caught by standard try catch blocks.  See this PAQ

http://www.experts-exchange.com/jsp/qManageQuestion.jsp?ta=cplusprog&qid=20126861
0
 
LVL 2

Expert Comment

by:LoungeLizard
ID: 6372246
One thing that is wrong with my example above is

if(String(Ex.ClassName()) == "Eoverflow")

other than that this should work in C++ builder (I compiled this with C++ builder 5 with no problems)

Remember it is NOT neccesary for you to throw overflow exception. That will be done automatically. You just have to catch it and do something about it.
0
 
LVL 14

Accepted Solution

by:
AlexVirochovsky earned 50 total points
ID: 6375427
Right code is:
int main(int argc, char **argv)
{
   double i, p;
   int inp;
   i = 1; p = 0.0;

   try {
       i= i/p;
       throw("EZeroDivide");
   }
   catch (Exception &Ex)
   {
      AnsiString szName = Ex.ClassName();
      if(!strcmp(szName.c_str(),"Eoverflow"))
       {
           puts ("Overflow");
           scanf ("%d", &inp);
       }

   }
       return 0;
}
0
 
LVL 14

Expert Comment

by:AlexVirochovsky
ID: 6389095
aavictor ???
0
 
LVL 4

Author Comment

by:aavictor
ID: 6391257
The signal is caught, but the program is still aborted
Is it possible that the function can return error code to
caller, and caller can still continue the next task.
0
 
LVL 4

Author Comment

by:aavictor
ID: 6395771
I can use setjmp for try/catch to resume the flow.
However, the signal is still passed and pops up the error
pop-up. If remove it, the application gets abnormal termination.
0
 
LVL 4

Author Comment

by:aavictor
ID: 6404873
For AlexVirochovsky

50 points more of how to resume the normal execution after
EZeroDivide and/Or EOverflow are ON. Otherwise, 50 only.

Case
The computation result of called functions can be
1. Overflow value over constant
2. Overflow value over zero where zero is a difference of very closet values (x,y) and end result is zero.
   note :  x <> y
3.  zero over zero
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
What is the real difference between C++ and Visual C++.NET? 7 120
Writing a parser for java language 4 85
c++ syntax question 9 52
White board coding practice 3 92
Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question