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

x
?
Solved

suppressing EFOpenErrors in IDE at design time

Posted on 2004-10-14
7
Medium Priority
?
314 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
[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
  • 2
  • 2
  • +1
7 Comments
 
LVL 6

Accepted Solution

by:
vadim_ti earned 2000 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
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…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Suggested Courses

730 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