Board index » delphi » Help with Trapping Runtime Errors in Borland Pascal 7.0

Help with Trapping Runtime Errors in Borland Pascal 7.0

Is there a way to trap runtime errors in Turbo Pascal 7.0?  My objective
is to trap (or display) the runtime error in a readable format before
the screen clears.  A majority of my clients run my program on Windows
95/98 operating systems. When a runtime error occurs, the message
displays for an instant and then clears because the shortcut to my
program is defined with 'Close on Exit' enabled.  I would prefer not to
disable 'Close on Exit' because most of clients would have trouble
trying to figure out how to get rid of the DOS window.  If there is a
way to trap and properly display these errors I would be most
appreciative in the technique.

I'm familiar with the RunError procedure and I am not sure I can include
that in my source where ever a runtime may occur. My source has been
writen and rewriten by several programmers, each with their own style,
and it would be an enormous task to predict where runtime errors could
occur.

Thanks in advance for any help.

mbd

 

Re:Help with Trapping Runtime Errors in Borland Pascal 7.0


I am replying to my own message in that I have solved my own problem. I
happened upon a message from Prof. Timo Salmi. In his message he has an
archive of 'Common Turbo Pascal Questions and Timo's Answers' at:
ftp://garbo.uwasa.fi/pc/ts/tsfaqp49.zip
I list this site in case others can not find it. I found exactly what I was
looking for and have read resources that he had mentioned. Thanks so much to
Timo.

p.s. The answer is to create your own Exit Procedure.

Quote
Michael Domke wrote:
> Is there a way to trap runtime errors in Turbo Pascal 7.0?  My objective
> is to trap (or display) the runtime error in a readable format before
> the screen clears.  A majority of my clients run my program on Windows
> 95/98 operating systems. When a runtime error occurs, the message
> displays for an instant and then clears because the shortcut to my
> program is defined with 'Close on Exit' enabled.  I would prefer not to
> disable 'Close on Exit' because most of clients would have trouble
> trying to figure out how to get rid of the DOS window.  If there is a
> way to trap and properly display these errors I would be most
> appreciative in the technique.

> I'm familiar with the RunError procedure and I am not sure I can include
> that in my source where ever a runtime may occur. My source has been
> writen and rewriten by several programmers, each with their own style,
> and it would be an enormous task to predict where runtime errors could
> occur.

> Thanks in advance for any help.

> mbd

Re:Help with Trapping Runtime Errors in Borland Pascal 7.0


Quote
Michael Domke <mdo...@waymark.net> wrote in message

news:388527C5.FCF10C49@waymark.net...

Quote
> Is there a way to trap runtime errors in Turbo Pascal 7.0?  My objective
> is to trap (or display) the runtime error in a readable format before
> the screen clears.

Create an exit procedure. This is a procedure declared Far, whose address
you store in the ExitProc variable, after you have saved the old value of
ExitProc in a variable somewhere. Inside the exit procedure, reset ExitProc,
check the value of the ErrorAddr variable, if it is NIL then you are exiting
without a run-time error, otherwise it is the address of your run-time error
and the error code is in ExitCode. Clear ErrorAddr to prevent the RTL from
reporting the error too.

So:
Var
  OldExitProc : Pointer;

Procedure ExitHandler; Far;
Begin
  ExitProc := OldExitProc;
  if ErrorAddr<>NIL then
  Begin
    Writeln('Error ',ExitCode,' at address ',
            Seg(ErrorAddr^),':',Ofs(ErrorAddr^));
    Readln;

    ErrorAddr := NIL;
      { Prevent re-reporting of the error
      }
  End;
End;

Procedure Die;
Begin
  RunError(123);
End;

Begin
  OldExitProc := ExitProc;
  ExitProc := @ExitHandler;

  Die;
End.

Other Threads