Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!wuarchive!zaphod.mps.ohio-state.edu!swrinde!ucsd!ucbvax!bloom-beacon!eru!hagbard!sunic!news.funet.fi!uwasa.fi!ts From: ts@uwasa.fi (Timo Salmi) Newsgroups: comp.lang.pascal Subject: Re: HANDLING FLOATING POINT OVERFLOW ERROR IN TP Message-ID: <1991Jan3.215007.28861@uwasa.fi> Date: 3 Jan 91 21:50:07 GMT References: <11637@j.cc.purdue.edu> Organization: University of Vaasa Lines: 50 In article <11637@j.cc.purdue.edu> zhou@brazil.psych.purdue.edu (Albert Zhou) writes: > > Whenever a floating point overflow error is encountered, the program >will unconditionally stop in Turbo Pascal. Is there a way of deactivating it >so as to let the programmer handle this type of error? > As I understand, there is no compiler derective that does it. Just >like {$I-} that enables the programmer to handle I/O errors. > Any clue will be greatly appreciated. 25. ***** Q: How can I trap a runtime error? A: What you are probably asking for is a method writing a program termination routine of your own. To do this, you have to replace Turbo Pascal's ExitProc with your own customized exec procedure. Several Turbo Pascal text books show ho to do this. See eg Tom Swan (1989), Mastering Turbo Pascal 5.5, Third edition, Hayden Books, pp. 440-454; Michael Yester (1989), Using Turbo Pascal, Que, pp. 376-382; Stephen O'Brien (1988), Turbo Pascal, Advanced Programmer's Guide, pp. 28-30; Tom Rugg & Phil Feldman (1989), Turbo Pascal Programmer's Toolkit, Que, pp. 510-515. Here is an example var OldExitProcAddress : Pointer; x : real; {$F+} procedure MyExitProcedure; {$F-} begin if ErrorAddr <> nil then begin writeln ('Runtime error number ', ExitCode, ' has occurred'); writeln ('The error address in decimal is ', Seg(ErrorAddr^):5,':',Ofs(ErrorAddr^):5); writeln ('That''s all folks, bye bye'); ErrorAddr := nil; ExitCode := 0; end; {... Restore the pointer to the original exit procedure ...} ExitProc := OldExitProcAddress; end; (* MyExitProcedure *) (* Main *) begin OldExitProcAddress := ExitProc; ExitProc := @MyExitProcedure; x := 7.0; writeln (1.0/x); x := 0.0; writeln (1.0/x); {The trap} x := 7.0; writeln (4.0/x); {We won't get this far} end. ................................................................... Prof. Timo Salmi (Moderating at anon. ftp site 128.214.12.3) School of Business Studies, University of Vaasa, SF-65101, Finland Internet: ts@chyde.uwasa.fi Funet: gado::salmi Bitnet: salmi@finfun