Solved

How can I get error number from exception

Posted on 1998-08-10
4
278 Views
Last Modified: 2010-04-04
Earler with pascal the error code number was geven by IOResult function.
But in delphi with exception handling how can I get the last error number for example I/O errors code.
0
Comment
Question by:Motaz
  • 2
4 Comments
 
LVL 10

Expert Comment

by:viktornet
ID: 1361828
If I'm getting you right here is an example..otherwise give some more details please....thanx

var

  F: file of Byte;
begin
  if OpenDialog1.Execute then begin
    AssignFile(F, OpenDialog1.FileName);
    {$I-}
    Reset(F);
    {$I+}
    if IOResult = 0 then
      MessageDlg('File size in bytes: ' + IntToStr(FileSize(F)),
        mtInformation, [mbOk], 0);
    else
      MessageDlg('File access error', mtWarning, [mbOk], 0);
  end;
end;

Regards,
Viktor Ivanov
0
 
LVL 8

Accepted Solution

by:
ZifNab earned 10 total points
ID: 1361829
Hi Motaz,

 if you use exceptions for your IO control then the exceptions you get are of type EInOutError :

type
 EInOutError = class(Exception)
   ErrorCode: Integer;
 end;

So the ErrorCode give the same result as IOResult in early pascal days (or still in delphi for compatibility?)

try
 ...
except
 on E: Exception do showMessage('ErrorCode: ', E.ErrorCode);
end;

Zif.
0
 
LVL 7

Author Comment

by:Motaz
ID: 1361830
Thanks ZifNab, you are a porfull Delphi programmer. I hope I become like you. I search for this error number for a long time. Thanks again for your help. But there is some bugs in your code but it isn't important, that is the correction :

procedure TForm1.Button1Click(Sender: TObject);
var
     f:file;
begin
  try
    AssignFile(f,'NonExist.err');
    Reset(f);
    closefile(f);
  except
  on E: EinoutError do
    showMessage('ErrorCode: '+IntToStr(E.ErrorCode));
  end; (*** end try ***)

end;

Motaz.
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1361831
Motaz, ok correct, there is a bug! Thanks for letting me know. I did it by hand, so there was a possibility for a bug. Zif.
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now