• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 762
  • Last Modified:

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

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
aavictor
Asked:
aavictor
  • 4
  • 3
  • 2
  • +1
1 Solution
 
LoungeLizardCommented:
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
 
LoungeLizardCommented:
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
 
aavictorAuthor Commented:
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
IainHereCommented:
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
 
LoungeLizardCommented:
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
 
AlexVirochovskyCommented:
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
 
AlexVirochovskyCommented:
aavictor ???
0
 
aavictorAuthor Commented:
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
 
aavictorAuthor Commented:
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
 
aavictorAuthor Commented:
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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 4
  • 3
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now