[comp.lang.pascal] Trapping

randy@oetl.UUCP (Randy O'Meara) (09/14/89)

	Does anyone know how to trap the fatal runtime errors in
	Turbo 5.0?  I'm interested in recovering from real math
	overflow.  Thanks.

-- 
Randy O'Meara		randy@oetl.Scf.Lockheed.Com
(408) 425-6249		...{pyramid,leadsv,lstc}!oetl!randy

dor@beach.cis.ufl.edu (Douglas R. Oosting) (09/15/89)

In article <486@oetl1.oetl.UUCP> randy@oetl.UUCP (Randy O'Meara) writes:
>
>	Does anyone know how to trap the fatal runtime errors in
>	Turbo 5.0?  I'm interested in recovering from real math
>	overflow.  Thanks.
>

Its fairly simple...you declare a procedure for error-handling somewhere
in your code.  Put a {$F+} and a {$F-} compiler directive around it
[force far call ON for the procedure, turn it back OFF afterwards]

Now, in your initialization code, make these two declarations...

ExitSave := ExitProc    [ExitProc is declared for you, ExitSave is a POINTER]
ExitProc := @MyErrorProc (or whatever)

The last statement of your error handler (refered to as MyErrorProc above)
must be   ExitProc := ExitSave

(Exiting a program is a chain procedure; this process inserts your trapper
*before* the Turbo one.  It will be called every time you exit, so you will
want to check the error condition to make sure you *need* to do anything.

Doug Oosting  
>-- 
>Randy O'Meara		randy@oetl.Scf.Lockheed.Com
>(408) 425-6249		...{pyramid,leadsv,lstc}!oetl!randy


--
Entropy Requires     | Douglas R. Oosting, University of Florida
No maintenance...    | dor@beach.cis.ufl.edu or Pendragon@oak.circa.ufl.edu 
   --Markoff Chaney  |...{mailrus|gatech}!uflorida!beach.cis.ufl.edu!dor
In the Society : Cadrys ap Dulas o Caereira, Barony of An Crosaire, Trimaris