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

Division By Zero Exception

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
erve
Asked:
erve
  • 4
  • 3
  • 3
  • +1
1 Solution
 
looneyCommented:
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
 
looneyCommented:
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
 
erveAuthor Commented:
I have already tryed this kind of solution, but not work.


0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
looneyCommented:
Did you use the (...) notation for the catch statment ?

0
 
erveAuthor Commented:
Yes, I use catch(...)
0
 
erveAuthor Commented:

0
 
chensuCommented:
Use the Toolhelp function: InterruptRegister(). The Tool Helper library supports INT_DIV0 (Divide-error exception). Please check with online help for more details.

0
 
erveAuthor Commented:
You have some example ?
0
 
chensuCommented:
You can check with Microsoft Visual C++ 1.x/Samples/Toolhelp/Thsample.c.

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

0
 
mar10Commented:
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

Become an Android App Developer

Ready to kick start your career in 2018? Learn how to build an Android app in January’s Course of the Month and open the door to new opportunities.

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