Solved

suppressing EFOpenErrors in IDE at design time

Posted on 2004-10-14
7
305 Views
Last Modified: 2010-08-05
Hi, I have a wee bit of code loading a stringlist from file

SL.loadfromfile(filename);

that occasionally raises an error. The file is often being read by my prog just as its being created by another PC & in these cases it seems to raise an  EFOpenError.  This is fine & is all handled at runtime, but I want to stop the error breaking execution at design time as I'm actually trying to track down another bug (so I don't want to set a blank application.onexception handler as a solution). I've tried using the {$I-} directive in the offending unit but this doesn't seem to do it. Can anyone help please.

Thanks, P
0
Comment
Question by:Pandora
  • 2
  • 2
  • 2
  • +1
7 Comments
 
LVL 6

Accepted Solution

by:
vadim_ti earned 500 total points
ID: 12314129
tools -> debugger options ->language exceptios

click Add

add EFopenError
place "v" to ignore this exception in debugger


and place code segment generated this exception in block something like it

while true do begin
   try
      LoadFromFile();
      break;      
   except
     sleep(200);
   end
end
0
 
LVL 5

Expert Comment

by:Hypoviax
ID: 12315343
vadim_ti  has the answer perfectly
0
 
LVL 1

Author Comment

by:Pandora
ID: 12317231
Hi Vadim, thx for your answer -  I did as you said
tools -> debugger options ->language exceptions
added EFOpenError and checked the box to exclude it.

However the program still breaks with an EFOpenError! I'm using delphi 5 on Win xp if that makes a difference

I also already had a try except block on the code, don't know if this makes a difference:

try
   SL.loadfromfile(MOFfilename);
   If IsEncrypted then //ie decrypt contents
      DecryptSLcontents;
   IsDirtyFlag:=false;
   result:=true;
   except
   on E:Exception do
      begin
      result:=false;
      //create a new blank file
      If IsCreateOnError then
         save;
      end;
   end;

Thanks
P

0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 6

Expert Comment

by:vadim_ti
ID: 12317367
what you mean breaks?

make a little test

add button to form, and onbuttonclickevent

procedure TForm1.Button4Click(Sender: TObject);
var
  a:cardinal;
  t:TResStringRec;
begin
  a:=2000;
  t.module := @a;
  t.identifier := 1;
  raise(efopenerror.Create(@t, 'a.a'));
end;

with debugger environment settings like above
programm does not break on this exception (at least in my comp)
if i clear "v" it yes breaks.

may be you have a problem in another segment of a code?
0
 
LVL 17

Expert Comment

by:Wim ten Brink
ID: 12318447
He means the code breaks IN DESIGNTIME! The code is part of some component and this component doesn't have an exception handler capturing this error silently when in designmode...

Basically, he needs something like:

try
except
  if not InDesignMode then raise;
end;

to reraise the error while he's in runtime but to keep it quiet in designtime.

There are several different tricks for this but the easiest on is to check if the component state is in design-mode. Thus, he has to alter the component and use:

procedure TYourComponent.YourMethod(YourParameters: YourTypes);
begin
  try
    // Load the file and see it crash and burn.
  except
    if not csDesigning in ComponentState then raise;
  end;
end;

Thus, in designtime it will just shut up... :-)
0
 
LVL 1

Author Comment

by:Pandora
ID: 12318557
Hi Vad,
Tried the test it works as it should so don't know why its being peculiar in the other project. It may be a deeper problem I giuess I'll have to explore more - but I've awarded the pts cos this would normally work it seems.

Alex thx for your comment too - that seems equally helpful as its code specific but I've only just spotted it so I'm sry u missed out on points (& vad got in 1st). But I shall have a play on those lines too. Thx alot & sorry for not spotting it.

best wishes
P
0
 
LVL 17

Expert Comment

by:Wim ten Brink
ID: 12319138
No problem, although I do consider Vad's solution pretty dangerous since you might up in an endless loop...

while true do begin
   try
      LoadFromFile();
      break;      
   except
     sleep(200);
   end;
end;

Now, what if the file you're trying to load is permanently unavailable, thus raising an exception every time you load it. It means that you will put your code to sleep permanently, with no way to respond to anything. Maybe a non-endless loop would be better...

  I := 3;
  while (I>0) do
  try
     LoadFromFile();
     I := 0;
   except
     Dec(I);
     if (I = 0) and not (csDesigning in ComponentState) then raise;
   end;

This will try to load the file three times, silently crashing in designtime and loudly crashing in runtime. :-)
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

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

Suggested Solutions

Title # Comments Views Activity
Machine not responding during CopyFile() 3 103
LAN or WAN ? 11 95
Delphi Yen format 3 45
How to save the image in the .cds File ClientDataSet? 1 22
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…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

792 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