[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

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

Posted on 2001-08-09
10
Medium Priority
?
748 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: 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!

 
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 150 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

650 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