Back!Trapping Errors


? Hi.
I have a realativly simple question: is it possible to trap errors in DJGPP after they occur? What I mean is if something like an FPE occurs, is it possible to have DJGPP run a function which attempts to correct the problem? This is probably a really stupid question, but thanks for your help.

! Yes, you can.
volatile int merr=0;
static unsigned int fpcw;
void math_handler(int sig){
   fpcw = _clear87() & 0xff;
   printf("SIGFPE: %x\n",fpcw);
   merr = fpcw;
}
int main(int argc, char **argv){
double foo,bar;   
  signal(SIGFPE,math_handler);
  foo=0.; bar = 1.;
  bar = bar/foo;
  return 0;
}
You also may want to include , say
 _fdlib_version = _SVID_;
 _control87(EM_UNDERFLOW, ~EM_UNDERFLOW);
 _control87(EM_INEXACT, ~EM_INEXACT);
and define your own int matherr(struct exception *e) to correct errors...