Solved

How can I get error number from exception

Posted on 1998-08-10
4
406 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
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…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Suggested Courses
Course of the Month7 days, 11 hours left to enroll

632 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