Solved

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

Posted on 2001-08-09
10
698 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
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…
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.

863 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

21 Experts available now in Live!

Get 1:1 Help Now