Solved

suppressing EFOpenErrors in IDE at design time

Posted on 2004-10-14
7
296 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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

746 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

12 Experts available now in Live!

Get 1:1 Help Now