Solved

Try/Except to suppress MsgBox from EInOutError

Posted on 2002-05-02
8
685 Views
Last Modified: 2010-05-18
Delphi 5 program runs in both Batch and Interactive mode.
When run in Batch mode I wish to suppress all msgboxs so that the run is not impeded.
This can be done by sprinkling  '$I'  comments throughout the program.
It should be possible to use try/except to trap all these EInOuterror  's between try AND except.
I find that during testing if I force one of the exceptions to be thrown , say by
writing to an unopened file, that a MsgBox comes up from the system and then my
exception handler code is executed.

 Am I missing something? Can I somehow stop the system from putting up the messagebox
 In my Exception handling code I want a MsgBox only if in Interactive mode and I want
 to log and error message regardless of the run mode.
 
 Below is an outline of what I tried:
 
/////// Begin $I
{$I-}
 Writeln(gfProgLog,'PROJECT_ID!   CASEID! IwLength(minutes) '); ///!!!!!!! noit open yet
{$I+}
 if IOResult <> 0 then
       Writeln(fLog,'Handle IO error by self.');
       
ASSIGNFILE( gfProgLog, 'c:\AR_Programmer.log' ); // open single LOG file
REWRITE( gfProgLog );      
\\\\\\ END $I


////// BEGIN Exception code
       
try

-->     ENTIRE PROCEDURE HERE <---

except      {end big try}
on  E :EInOutError do
begin  
  if gbBatchMode = false then
    MessageDlg('AR:I/O error ' + E.Message + ' Line# ' + IntToStr(nLineCnt) + ' file: ' + slFileList[I], mtWarning, [mbOk], 0)
    { specific exception-handling code }
  else
  begin    
    writeln(fLog,'AR:I/O error ' + sTemp + ' Line# ' + IntToStr(nLineCnt) + ' file: ' + slFileList[I] );
  end;
end ;
on  E :EStringListError do
begin
        ......
end;
else
  begin
    if gbBatchMode = false then
      MessageDlg('AR:Unhandled non-IO/non Stringlist error :no message yet ' + ' Line# ' + IntToStr(nLineCnt) + ' file: ' + slFileList[I], mtWarning, [mbOk], 0)
    else
      writeln(fLog,'AR: unhandled non- IO error ' + sTemp + ' Line# ' + IntToStr(nLineCnt) + ' file: ' + slFileList[I] );
  end;
    { default exception-handling code };
end;  {except}


   
0
Comment
Question by:mebarron
  • 6
  • 2
8 Comments
 
LVL 6

Expert Comment

by:DrDelphi
ID: 6986469
Can't you use a TApplicationEvents' OnException eventhandler for that?



Good luck!!
0
 
LVL 6

Expert Comment

by:DrDelphi
ID: 6986477
For example:

procedure TForm1.ApplicationEvents1Exception(Sender: TObject;
  E: Exception);
begin
 if (E is EInOutError) then
 begin
   //yada
   //yada
   //yada
   //yada
 end;
end;




0
 
LVL 6

Expert Comment

by:DrDelphi
ID: 6986478
For example:

procedure TForm1.ApplicationEvents1Exception(Sender: TObject;
  E: Exception);
begin
 if (E is EInOutError) then
 begin
   //yada
   //yada
   //yada
   //yada
 end;
end;




0
ScreenConnect 6.0 Free Trial

Discover new time-saving features in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

 

Author Comment

by:mebarron
ID: 6987345
I created
 procedure TForm1.ApplicationEvents1Exception
As you advised. Is there anyway to get the execution
to resume where the error occurred? Say the prog is
processing a series of files. It would be great to be
able to continue processing with the next file
0
 
LVL 6

Expert Comment

by:DrDelphi
ID: 6988344
Hmmm... well, it seems that you're using a TStringList to keep track of the files that you're processing. If this is so, then I would imagine that you should be able to delete the file name once you're done with it. Now, in the OnException, you could simply call the routine again that processes the files. It might be necessary to delete the first item from the TStringlist first, however, since presumably that was the one that gave you an error in the first place (it wasn't processed and deleted within the processing routine).Of course the filelist  will have to be global. Psuedocode looks like this:



Routine -> Process files
OnException ->deletes the first file in the que and calls routine to continue.


Good luck!!

0
 
LVL 6

Accepted Solution

by:
DrDelphi earned 50 total points
ID: 6988346
Better PsuedoCode:

Routine:
   while Filelist.count>0
   Process file
   Delete Filename from fileList
   Continue;

OnException:
       Delete FileList[0]//get rid of the offending file
       possibly WriteToLog('FileList[0] failed')
       Call Routine;


Good luck!!

0
 

Author Comment

by:mebarron
ID: 6992010
Many Thanks Dr Delphi
I really like the idea of using index == 0
together w/ deletion of string.
I'll be back. Mark
0
 
LVL 6

Expert Comment

by:DrDelphi
ID: 7006538
Cheers.
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

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 I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

773 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