Solved

suppressing EFOpenErrors in IDE at design time

Posted on 2004-10-14
7
311 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 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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] 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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Suggested Courses
Course of the Month6 days, 13 hours left to enroll

623 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