Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How can I get error number from exception

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
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…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

670 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