Solved

Division By Zero Exception

Posted on 1997-02-17
11
537 Views
Last Modified: 2012-05-04
How I can implement a Division By Zero exception handling into a DLL function using Borland C/C++ 5.01 both for 32 and 16 bit environment.

Many Thansk.
0
Comment
Question by:erve
  • 4
  • 3
  • 3
  • +1
11 Comments
 

Expert Comment

by:looney
ID: 1161991
All I can suggest is using try / catch blocks in your code to handle any errors if they occur.
try
{
pWebInterface_i->writeBack( genBrowseScreen() );
            }
            catch(IKStackException * /*pException*/)
              {
                  //pException->addFunctionInfo("KService::addSession");
                    //comStackException(pException);
               }
               catch(IKAPIException * /*pException*/ )
               {
                  printf("error\n");
                    //comAPIException(pException);
               }
               catch(long int)
               {
                  printf("error\n");
                    //comMemException();
               }
            catch(...)
               {
                  DWORD lastError_i = GetLastError();
                  printf("error\n");
                  //KAPIException *pAPIException = new KAPIException( CLIENT_UNKNOWN_KERRORCODE_APIEXCEPTION );         
          }

Are you looking for some function like _set_new_handler but for divide by zero errors. I don't think one exists.

Tom.
0
 

Expert Comment

by:looney
ID: 1161992
Sorry about the last posting , hit the wrong key combination ...

All I can suggest is using try / catch blocks in your code to handle any errors if they occur.

try
{
   divide by zero code;
}
catch(...)
{
   handle error
}

Are you looking for some function like _set_new_handler but for divide by zero errors. I don't think one exists.

Tom.
0
 

Author Comment

by:erve
ID: 1161993
I have already tryed this kind of solution, but not work.


0
ScreenConnect 6.0 Free Trial

At ScreenConnect, partner feedback doesn't fall on deaf ears. We collected partner suggestions off of their virtual wish list and transformed them into one game-changing release: ScreenConnect 6.0. Explore all of the extras and enhancements for yourself!

 

Expert Comment

by:looney
ID: 1161994
Did you use the (...) notation for the catch statment ?

0
 

Author Comment

by:erve
ID: 1161995
Yes, I use catch(...)
0
 

Author Comment

by:erve
ID: 1161996

0
 
LVL 23

Accepted Solution

by:
chensu earned 200 total points
ID: 1161997
Use the Toolhelp function: InterruptRegister(). The Tool Helper library supports INT_DIV0 (Divide-error exception). Please check with online help for more details.

0
 

Author Comment

by:erve
ID: 1161998
You have some example ?
0
 
LVL 23

Expert Comment

by:chensu
ID: 1161999
You can check with Microsoft Visual C++ 1.x/Samples/Toolhelp/Thsample.c.

0
 
LVL 23

Expert Comment

by:chensu
ID: 1162000
You can also check with the book by Jim Conger from The Waite Group: Windows API New Testament.

0
 

Expert Comment

by:mar10
ID: 1162001
try this:

--- start of example

// needs:
#include <float.h>
#include <signal.h>

typedef void (*SigHandler_T) (int);

// FPE Handler:
void cbSigFPE (int* piRegs)
{
    int iType = ( *((int*)&piRegs+1) );       // FPE_... defined in float.h
    // ...
    signal (SIGFPE, (SigHandler_T)cbSigFPE);  //  reinstall signal handler
}

// install FPE handler:
signal (SIGFPE, (SigHandler_T)cbSigFPE);

--- end of example

Don't use C++ runtime lib funks in signal handlers (semaphore deadlock might occur)

You may also mask out FPEs:
    UINT uExcpt = EM_INVALID|EM_DENORMAL|EM_ZERODIVIDE|EM_OVERFLOW|EM_UNDERFLOW|EM_INEXACT;
    _control87 (uExcpt, MCW_EM);

martin wendt
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
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 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 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.

770 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