Solved

Division By Zero Exception

Posted on 1997-02-17
11
516 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
Comment Utility
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
Comment Utility
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
Comment Utility
I have already tryed this kind of solution, but not work.


0
 

Expert Comment

by:looney
Comment Utility
Did you use the (...) notation for the catch statment ?

0
 

Author Comment

by:erve
Comment Utility
Yes, I use catch(...)
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

Author Comment

by:erve
Comment Utility

0
 
LVL 23

Accepted Solution

by:
chensu earned 200 total points
Comment Utility
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
Comment Utility
You have some example ?
0
 
LVL 23

Expert Comment

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

0
 
LVL 23

Expert Comment

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

0
 

Expert Comment

by:mar10
Comment Utility
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
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 use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

771 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

10 Experts available now in Live!

Get 1:1 Help Now