delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/03/05/02:45:42

From: Thomas Demmer <demmer AT LSTM DOT Ruhr-UNI-Bochum DOT De>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Error Trapping -- How??
Date: Thu, 05 Mar 1998 08:33:16 +0100
Organization: Lehrstuhl fuer Stroemungsmechanik
Lines: 53
Message-ID: <34FE553C.B9113BD4@LSTM.Ruhr-UNI-Bochum.De>
References: <34FE22ED DOT 6BCF0CCE AT concentric DOT net>
NNTP-Posting-Host: bvb.lstm.ruhr-uni-bochum.de
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

D. Huizenga wrote:
> 
> 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 <libm/math.h>,
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...
  

-- 
Ciao
Tom

*************************************************************
* Thomas Demmer                                             *
* Lehrstuhl fuer Stroemungsmechanik                         *
* Ruhr-Uni-Bochum                                           *
* Universitaetsstr. 150                                     *
* D-44780  Bochum                                           *
* Tel: +49 234 700 6434                                     *
* Fax: +49 234 709 4162                                     *
* http://www.lstm.ruhr-uni-bochum.de/~demmer                *
*************************************************************

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019