Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2000-09

error messages

11 messages · 8 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Sidney Cave

I have looked through the documentation and have not found anything that shows how to get descriptive error messages to be displayed if a program terminates with an error. It would be nice to have it report "ERROR 200, Division by zero." instead of just "ERROR 200". Has anyone found this in the documentation or have an idea as to how to do this?

Sid Cave

=====
Sid Cave

__________________________________________________ Do You Yahoo!?
Yahoo! Mail - Free email you can access from anywhere! http://mail.yahoo.com/

Adam Naumowicz
to Sidney Cave
Sidney Cave wrote 11 lines
I have looked through the documentation and have not found anything that shows how to get descriptive error messages to be displayed if a program terminates with an error. It would be nice to have it report "ERROR 200, Division by zero." instead of just "ERROR 200". Has anyone found this in the documentation or have an idea as to how to do this? Sid Cave

You just have to install your own (more sophisticated) ExitProc handler.

Adam Naumowicz

--------------------------------------
WWW: http://math.uwb.edu.pl/~adamn/
--------------------------------------

Sidney Cave

Thanks to Adam Naumowicz for the hint on using
ExitProc for generating descriptive error messages. I gave that a try and it seems to work fine. This was my first attempt at writing a unit, and some of this was by trial and error. If anyone who is interested would please let me know if I did anything wrong, I would appreciate it.

Also, is there a procedure for forcing a program to generate an error of a given type? I took a look at the docs and could not find anything. It may be there, but I just don't know what it is called to even to run a search. I would hesitate to call this little project done until I could test it by forcing all of the
various errors. As it stands, I only checked two or three.

Sid Cave
======================================
unit ErrorMsg;
interface
implementation
var
  OldExitProc:pointer;
procedure ErrorMessage;
begin
  if ErrorAddr  nil then
    begin
      case ExitCode of
        1: writeln ('Invalid function number.');
        2: writeln ('File not found.');
        3: writeln ('Path not found.');
        4: writeln ('Too many open files.');
        5: writeln ('File access denied.');
        6: writeln ('Invalid file handle.');
        12: writeln ('Invalid file access code.');
        15: writeln ('Invalid drive number.');
        16: writeln ('Cannot remove current
directory.');
        17: writeln ('Cannot rename across drives');
        100: writeln ('Disk read error.');
        101: writeln ('Disk write error.');
        102: writeln ('File not assigned.');
        103: writeln ('File not open.');
        104: writeln ('File not open for input.');
        105: writeln ('File not open for output.');
        106: writeln ('Invalid numeric format.');
        150: writeln ('Disk is write-protected.');
        151: writeln ('Bad drive request struct
length.');
        152: writeln ('Drive not ready.');
        154: writeln ('CRC error in data.');
        156: writeln ('Disk seek error.');
        157: writeln ('Unknown media type.');
        158: writeln ('Sector not found.');
        159: writeln ('Printer out of paper.');
        160: writeln ('Device write fault.');
        161: writeln ('Device read fault.');
        162: writeln ('Hardware failure.');
        200: writeln ('Division by zero.');
        201: writeln ('Range check error.');
        202: writeln ('Stack overflow error.');
        203: writeln ('Heap overflow error.');
        204: writeln ('Invalid pointer operation');
        205: writeln ('Floating point overflow.');
        206: writeln ('Floating point underflow.');
        207: writeln ('Invalid floating point
operation.');
        210: writeln ('Object not initialized.');
        211: writeln ('Call to abstract method.');
        212: writeln ('Stream registration error.');
        213: writeln ('Collection index out of
range.');
        214: writeln ('Collection overflow error.');
        216: writeln ('General protection fault.');
        217: writeln ('Unhandled exception
occurred.');
        227: writeln ('Assertion failed error.');
        else writeln ('Unknown error.');
      end;
    end;
  Exitproc:=OldExitProc;
end;
begin
  OldExitProc:=ExitProc;
  ;
end.
===================================

=====
Sid Cave

__________________________________________________ Do You Yahoo!?
Send instant messages & get email alerts with Yahoo! Messenger. http://im.yahoo.com/

Unknown author
Show quoted text 6 lines
procedure ErrorMessage; begin if ErrorAddr nil then begin case ExitCode of 1: writeln ('Invalid function number.');

<cut>

Show quoted text 6 lines
227: writeln ('Assertion failed error.'); else writeln ('Unknown error.'); end; end; Exitproc:=OldExitProc; end;

Small hint: place the ExitProc:=OldExitProc as the first statement in the procedure. If not done and your procedure gives an error it'll get into an infinite loop.

Jonas Maebe
Also, is there a procedure for forcing a program to generate an error of a given type?

Runerror() (e.g. runerror(201))

Jonas

Adam Naumowicz
to Sidney Cave: Thanks to Adam Naumowicz for the hint on using ExitProc for generating descriptive error…
Sidney Cave wrote 95 lines
Thanks to Adam Naumowicz for the hint on using ExitProc for generating descriptive error messages. I gave that a try and it seems to work fine. This was my first attempt at writing a unit, and some of this was by trial and error. If anyone who is interested would please let me know if I did anything wrong, I would appreciate it. Also, is there a procedure for forcing a program to generate an error of a given type? I took a look at the docs and could not find anything. It may be there, but I just don't know what it is called to even to run a search. I would hesitate to call this little project done until I could test it by forcing all of the various errors. As it stands, I only checked two or three. Sid Cave ====================================== unit ErrorMsg; interface implementation var OldExitProc:pointer; procedure ErrorMessage; begin if ErrorAddr nil then begin case ExitCode of 1: writeln ('Invalid function number.'); 2: writeln ('File not found.'); 3: writeln ('Path not found.'); 4: writeln ('Too many open files.'); 5: writeln ('File access denied.'); 6: writeln ('Invalid file handle.'); 12: writeln ('Invalid file access code.'); 15: writeln ('Invalid drive number.'); 16: writeln ('Cannot remove current directory.'); 17: writeln ('Cannot rename across drives'); 100: writeln ('Disk read error.'); 101: writeln ('Disk write error.'); 102: writeln ('File not assigned.'); 103: writeln ('File not open.'); 104: writeln ('File not open for input.'); 105: writeln ('File not open for output.'); 106: writeln ('Invalid numeric format.'); 150: writeln ('Disk is write-protected.'); 151: writeln ('Bad drive request struct length.'); 152: writeln ('Drive not ready.'); 154: writeln ('CRC error in data.'); 156: writeln ('Disk seek error.'); 157: writeln ('Unknown media type.'); 158: writeln ('Sector not found.'); 159: writeln ('Printer out of paper.'); 160: writeln ('Device write fault.'); 161: writeln ('Device read fault.'); 162: writeln ('Hardware failure.'); 200: writeln ('Division by zero.'); 201: writeln ('Range check error.'); 202: writeln ('Stack overflow error.'); 203: writeln ('Heap overflow error.'); 204: writeln ('Invalid pointer operation'); 205: writeln ('Floating point overflow.'); 206: writeln ('Floating point underflow.'); 207: writeln ('Invalid floating point operation.'); 210: writeln ('Object not initialized.'); 211: writeln ('Call to abstract method.'); 212: writeln ('Stream registration error.'); 213: writeln ('Collection index out of range.'); 214: writeln ('Collection overflow error.'); 216: writeln ('General protection fault.'); 217: writeln ('Unhandled exception occurred.'); 227: writeln ('Assertion failed error.'); else writeln ('Unknown error.'); end; end; Exitproc:=OldExitProc; end; begin OldExitProc:=ExitProc; ; end. =================================== ===== Sid Cave

I don't know if in this situation it is really importent or being just a programming prejudice (at least old good TP help says so), that the first statement in your exit procedure should reinstall the saved one. So maybe you should place your ExitProc:=OldExitProc at the beginning of ErrorMessage.
If you want to test your program just try calling RunError with all error codes.

Adam Naumowicz

--------------------------------------
WWW: http://math.uwb.edu.pl/~adamn/
--------------------------------------

Lee, John

when you've checked it could be useful contributed unit IMO

Earlier message 5 lines
-----Original Message----- From: Sidney Cave Sent: 19 September 2000 13:16 To: Subject: Re: [fpc-pascal]error messages
Johann Glaser
to Marco van de Voort: Hmm. HALT(X); ?

Hi!

> Also, is there a procedure for forcing a program to > generate an error of a given type? Hmm. HALT(X); ?

No, Halt(x) will only set the ExitCode of the program.

There will be no runtime error!

But, when a runtime error occurs, it exits with Halt(ErrNo); (so it is opposite as you perhaps thought)

Bye
Hansi

Sent through GMX FreeMail - http://www.gmx.net
Pierre Muller
you wrote 18 lines
> procedure ErrorMessage; > begin > if ErrorAddr nil then > begin > case ExitCode of > 1: writeln ('Invalid function number.'); <cut> > 227: writeln ('Assertion failed error.'); > else writeln ('Unknown error.'); > end; > end; > Exitproc:=OldExitProc; > end; Small hint: place the ExitProc:=OldExitProc as the first statement in the procedure. If not done and your procedure gives an error it'll get into an infinite loop.

No exitproc is allways reset to nil before calling next exit procedure that is into the chain.
So if an error occurs inside this code, the other exit procedures would not be
called, that all, you would get into a infinite loop.

You can get into an infinite loop of you set exitproc pointer into a function that gets called more than once, so a good pratice is to either write this in the start code of the unit directly or to do something like

  const
    oldexitproc : pointer = nil;
  if oldexitproc=nil then
    begin
      oldexitproc:=exitproc;
      ;
    end;
Sidney Cave

Done. Version 1.0 of errormsg is now in the
miscellaneous section of contributed units.

John" wrote 15 lines
when you've checked it could be useful contributed unit IMO -----Original Message----- From: Sidney Cave Sent: 19 September 2000 13:16 To: Subject: Re: [fpc-pascal]error messages _______________________________________________ fpc-pascal maillist -

http://lists.freepascal.org/mailman/listinfo/fpc-pascal

=====
Sid Cave

__________________________________________________ Do You Yahoo!?
Send instant messages & get email alerts with Yahoo! Messenger. http://im.yahoo.com/