Solved

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

Posted on 2001-08-09
10
694 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
 
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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…

747 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now