Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How can I get error number from exception

Posted on 1998-08-10
4
Medium Priority
?
507 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 30 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses

876 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